2015-10-05 64 views
0

我已經開始使用「ngNewRouter」。在我的應用程序中,使用javascript我需要在多個組件之間切換。我已經使用$location.path(path);,但它不一致。以下是詳細信息。

//定義路線

$router.config([ 
      {path: "/", redirectTo: "userauthentication"}, // The default URL is redirected to userauthentication component. 
      {path: "/userauthentication", component: "userauthentication"}, 
      {path: "/adminview", component: "adminview"}, 
      {path: "/clubonboarding/:clubid", component: "clubonboarding"}, 
      {path: "/membermanagement", component: "membermanagement"} 
     ]); 

$locationProvider.html5Mode(true); 

守則,正在努力:

$location.path("adminview"); 

守則,不工作:

$location.path("userauthentication"); 

它作爲它工作在幾個地方讓我感到吃驚和不適用於其他人。我在這裏錯過了什麼。

請指教。

+0

「不工作」是什麼意思?你有錯誤嗎?你有錯誤的頁面?觸發此代碼的事件是否永遠不會觸發?目前尚不清楚問題出在哪裏。 – Claies

+0

是的,事件被觸發,但視圖不會改變。 – joy

回答

0

你的路徑是相對的而不是絕對的。

如果您在查看/clubonboarding/:clubid,並且您想要轉至userauthentication,路由器會將相對路徑解析爲/clubonboarding/userauthentication

+0

我試過用「/ userauthentication」但它不工作,我看到URL改爲「/ userauthentication」並且很快回到「/ clubonboarding /:clubid」 – joy

+0

然後檢查網絡協議。它試圖加載'userauthentication'模板嗎?有沒有錯誤?所有資源是否都會返回正確的內容?當你使用'html5Mode'時,它可能會返回默認的'index.html'。 – Michael

+0

我已添加代碼重定向/ userauthentication刷新頁面/ clubonboarding /:clubid視圖。在頁面刷新時,它加載index.html,並暫時將URL更改爲/ userauthentication並返回到/ clubonboarding /:clubid。我檢查了「userauthentication」的網絡調用和未加載模板。我相信我錯過了一些東西......但不知道是什麼。 – joy