-1
我的Angular 4應用程序中的路由器鏈接在點擊時引發錯誤。他們一直在努力,直到我實現了一個用戶登錄組件。當應用程序加載時,它檢查用戶是否登錄。如果不是,則將它們發送到登錄組件this.router.navigate(['login'])
。一旦用戶成功登錄,我打電話this.router.navigate([''])
和應用程序的其餘部分正常顯示。然後,當單擊該應用程序的主要區域的鏈接,這個錯誤被拋出:Angular 4路由器鏈接重定向後不工作
TypeError: Cannot read property 'component' of undefined
at PreActivation.traverseRoutes (router.umd.js:4259)
at router.umd.js:4240
at Array.forEach (<anonymous>)
at PreActivation.traverseChildRoutes (router.umd.js:4239)
at PreActivation.traverseRoutes (router.umd.js:4268)
at router.umd.js:4240
at Array.forEach (<anonymous>)
at PreActivation.traverseChildRoutes (router.umd.js:4239)
at PreActivation.traverse (router.umd.js:4186)
at MapSubscriber.project (router.umd.js:4032)
at PreActivation.traverseRoutes (router.umd.js:4259)
at router.umd.js:4240
at Array.forEach (<anonymous>)
at PreActivation.traverseChildRoutes (router.umd.js:4239)
at PreActivation.traverseRoutes (router.umd.js:4268)
at router.umd.js:4240
at Array.forEach (<anonymous>)
at PreActivation.traverseChildRoutes (router.umd.js:4239)
at PreActivation.traverse (router.umd.js:4186)
at MapSubscriber.project (router.umd.js:4032)
at resolvePromise (zone.js:770)
at resolvePromise (zone.js:741)
at zone.js:818
at ZoneDelegate.invokeTask (zone.js:424)
at Object.onInvokeTask (core.umd.js:4143)
at ZoneDelegate.invokeTask (zone.js:423)
at Zone.runTask (zone.js:191)
at drainMicroTaskQueue (zone.js:584)
at HTMLDivElement.ZoneTask.invoke (zone.js:490)
的聯繫,如果在登錄過程中被關閉(用戶直接發送到主屏幕)工作得很好。任何人有任何信息給我?謝謝!
UPDATE:
這裏是我的路由器配置:
const routes: Routes = [
{
path: 'main',
component: MainComponent,
children: [
{ path: 'source/:source', component: ListComponent }
]
},
{ path: 'login', component: LoginComponent },
{ path: '', redirectTo: 'main/source/My workstation', pathMatch: 'full' },
{ path: '**', redirectTo: 'main/source/My workstation', pathMatch: 'full' }
];
請將您的路由配置添加到y我們的問題 –