2017-02-11 153 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