Angular2 路由,parent child -- 路由组件 vs 视图组件
Angular2 routing, parent child -- route component vs view component
我正在开发 Angular2 应用程序,目前我们处于 beta-17,因为发布候选版本不再支持捆绑并破坏了一切(那是另一回事)。
我理解parent和child路由之间的关系应该是child如果要有路由就必须是"routing component"。这是有道理的,对 - 但如果我想要一个 parent "routing component",它有一个 child "view component" 作为 parent 到child "routing component"?
.
├── app.component // Has two child routes, both are "view components"
├── plan.component
└── design.component // View component, route "/design/:id/..."
├── header.component
├── nav-and-body.component // Routing component
└── footer.component
我有一个 top-level 应用程序,它有两条路线,/plan/:id/...
和 /design/:id/...
路线。如您所见,我希望这些将用作其他 "routing components" 的 parent。假设我们在 "design" 路由中,我们试图导航到 NavAndBodyComponent
中定义的 child 路由,它不起作用,也不会抛出错误。
我相信这是因为我有一个 parent "routing component",它有一个 child "view component",它有一个嵌套的 "routing component" - 如何在不更改此层次结构的情况下解决此问题?
视图组件按预期加载:
URL: localhost:5000/design/10
但是当我尝试导航到嵌套的 child 路由时,URL 变为
URL: localhost:5000/model
我想要(和预期):
URL: localhost:5000/design/10/model
更新
这里很详细Plunker
!
问题是在根组件以外的组件上添加ROUTER_PROVIDERS
引起的。
如何防止在每次激活路由时添加动态添加的路由,请参阅
我正在开发 Angular2 应用程序,目前我们处于 beta-17,因为发布候选版本不再支持捆绑并破坏了一切(那是另一回事)。
我理解parent和child路由之间的关系应该是child如果要有路由就必须是"routing component"。这是有道理的,对 - 但如果我想要一个 parent "routing component",它有一个 child "view component" 作为 parent 到child "routing component"?
.
├── app.component // Has two child routes, both are "view components"
├── plan.component
└── design.component // View component, route "/design/:id/..."
├── header.component
├── nav-and-body.component // Routing component
└── footer.component
我有一个 top-level 应用程序,它有两条路线,/plan/:id/...
和 /design/:id/...
路线。如您所见,我希望这些将用作其他 "routing components" 的 parent。假设我们在 "design" 路由中,我们试图导航到 NavAndBodyComponent
中定义的 child 路由,它不起作用,也不会抛出错误。
我相信这是因为我有一个 parent "routing component",它有一个 child "view component",它有一个嵌套的 "routing component" - 如何在不更改此层次结构的情况下解决此问题?
视图组件按预期加载:
URL: localhost:5000/design/10
但是当我尝试导航到嵌套的 child 路由时,URL 变为
URL: localhost:5000/model
我想要(和预期):
URL: localhost:5000/design/10/model
更新
这里很详细Plunker
!
问题是在根组件以外的组件上添加ROUTER_PROVIDERS
引起的。
如何防止在每次激活路由时添加动态添加的路由,请参阅