2015-10-05 45 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