2017-02-11 137 views
1

我正在建立ananglar应用程序,其中所有的东西都能正常工作,除了只在某些情况下或某些时候路由。有时路由不能正常工作

我用这导航到主页:

this._router.navigate([ '']);

export const LoginRoutes: Route[] = [ 
    { 
     path: '', 
     component: LoginComponent, 
    }, 
    { 
     path: 'signup', 
     component: SignUpComponent 
    } 
]; 

当我页:

http://localhost:3000/dashboard/viewproduct

,点击退出按钮里面,我要前往某个登录组件的正常使用,但有时它被卡住和在同一页导航我,即:

http://localhost:3000/dashboard/viewproduct 

我无法弄清楚什么是错误的? 请建议是否有其他人也面临这个问题。

+0

可能重复[无法匹配任何路线。 URL段:'':当试图使用子路由和Ng2](http://stackoverflow.com/questions/40566685/cannot-match-any-routes-url-segment-when-trying-to-use-child-航线和ng) –

+0

嗯...不知道,但它的工作好所有的时间。只是我登录到我的应用程序,让它闲置30分钟,然后我面临这个问题。清除历史后再次工作。 – Rohitesh

回答

0

如果你有空路径路由,不需要childrenredirectTo然后使用pathMatch: 'full'

export const LoginRoutes: Route[] = [ 
{ 
    path: '', 
    component: LoginComponent, 
    pathMatch: 'full' 
}, 
{ 

告诉路由器它可以阻止试图符合其它路线。

+0

这也不起作用。但是,在清理历史记录后,它再次工作 – Rohitesh

+0

使用'this._router.navigate(['/']);'用'/',否则路由器将假设一条相对于当前路由的路由。路由定义应该不**具有前导'/',但'routerLink'或'router.navigate(...)'中的绝对路由应该。 –

+0

这也不起作用 – Rohitesh