在我Angular2應用程序,我有一個路由模塊如下所示:奇怪的路由器行爲
RouterModule.forChild([{
path: '',
component: HomeComponent,
children: [
{ path: '', redirectTo: 'explorer/0' },
{ path: 'explorer', redirectTo: 'explorer/0' },
{
path: 'explorer/:id',
component: EntitiesExplorerComponent,
children: [
{ path: 'details', component: EntityDetailsComponent }
]
},
]
},
正如你可以看到explorer
路徑有一個孩子。
奇怪的是,如果我導航到/explorer/1
我得到一個錯誤。 但是,如果我導航到/explorer/1/details
一切正常。
我想介紹一個探險家,當我去/explorer/ID
和實體的細節,當我去/explorer/ID/details
。
這是錯誤:(好像它不承認/explorer/ID
)
error_handler.js:47 EXCEPTION: Uncaught (in promise): TypeError: Cannot read property 'routes' of undefined
TypeError: Cannot read property 'routes' of undefined
at getChildConfig (http://localhost:4200/main.bundle.js:61682:35)
at Recognizer.processSegmentAgainstRoute (http://localhost:4200/main.bundle.js:61648:27)
謝謝菲利普。 在我的用例EntityDetailsComponent應該在EntitiesExplorerComponent上方。所以我需要同時顯示它們。 這就是爲什麼EntityDetailsComponent是EntityDetailsComponent的孩子。* 我注意到如果我把一個FakeComponent作爲EntitiesExplorerComponent的子元件:{path:'',component:Fake}它可以工作..但是也許有一個更乾淨的解決方案 – user3471528