diff --git a/src/Wt/WMenu.C b/src/Wt/WMenu.C
index 62f7884..8f3092a 100644
--- a/src/Wt/WMenu.C
+++ b/src/Wt/WMenu.C
@@ -299,8 +299,15 @@ void WMenu::internalPathChanged(const std::string& path)
     std::string value = app->internalPathNextPart(basePath_);
 
     for (unsigned i = 0; i < items_.size(); ++i) {
-      if (items_[i]->pathComponent() == value
-	  || items_[i]->pathComponent() == (value + '/')) {
+      std::size_t t = items_[i]->pathComponent().find('/', 0);
+      std::string firstPartOfPath;
+      
+      if (t == std::string::npos)
+        firstPartOfPath = items_[i]->pathComponent();
+      else
+        firstPartOfPath = items_[i]->pathComponent().substr(0, t);
+      
+      if (firstPartOfPath == value || firstPartOfPath == (value + '/')) {
 	items_[i]->setFromInternalPath(path);
 	return;
       }
@@ -309,8 +316,17 @@ void WMenu::internalPathChanged(const std::string& path)
     if (!value.empty())
       wApp->log("error") << "WMenu: unknown path: '"<< value << "'";
     else
-      select(-1, false);
+      select(0, false);
+    
+  } else if(path.length() < basePath_.length()) {
+    
+    std::string current = Utils::terminate(path, '/');
+    
+    if (basePath_.substr(0, current.length()) == current) {
+      select(0, false);
+    }
   }
+
 }
 
 void WMenu::select(WMenuItem *item)
diff --git a/src/Wt/WMenuItem b/src/Wt/WMenuItem
index 8587b9e..e9db4bb 100644
--- a/src/Wt/WMenuItem
+++ b/src/Wt/WMenuItem
@@ -131,7 +131,7 @@ public:
    * \sa setPathComponent()
    */
   virtual std::string pathComponent() const;
-
+  
   /*! \brief Returns the menu.
    */
   WMenu *menu() const { return menu_; }
diff --git a/src/Wt/WMenuItem.C b/src/Wt/WMenuItem.C
index 9e9f7ad..39ac1cb 100644
--- a/src/Wt/WMenuItem.C
+++ b/src/Wt/WMenuItem.C
@@ -93,7 +93,7 @@ std::string WMenuItem::pathComponent() const
 {
   return pathComponent_;
 }
-
+  
 void WMenuItem::setPathComponent(const std::string& path)
 {
   customPathComponent_ = true;
@@ -230,6 +230,11 @@ void WMenuItem::setFromInternalPath(const std::string& path)
   if (menu_->contentsStack_
       && menu_->contentsStack_->currentWidget() != contents())
     menu_->select(menu_->indexOf(this), false);
+  
+  if ((menu_->internalBasePath() + pathComponent_) != path
+      && (menu_->internalBasePath() + pathComponent_ + "/") != path) {
+    setPathComponent(path.substr(menu_->internalBasePath().length()));    
+  }
 }
 
 void WMenuItem::select()
