在我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