Angular2: 子路由中的递归路由

3
在Angular 2中,有这样一个路由:
{ path: 'contents/:id', component: ContentComponent }

当访问 /contents/1 时,这个功能非常完美。

假设 ContentComponent 有许多 ContentComponent 子组件,换句话说,Content 有许多 Contents。

是否可以使用子组件使此路由递归?例如:/contents/1/contents/20、/contents/1/contents/20/contents/54、/contents/1/contents/20/contents/54/contents/34324


你目前找到任何解决方案了吗? - Sadok Mtir
@SadokMtir 不是的。我改了我的应用程序,避免嵌套和递归路由。现在它们都是“平”的:/{modelname}/{id},我避免使用/{modelname}/{id}/{anothermodelname}/{otherid}。 - Christian Benseler
2个回答

0

你尝试过使用子元素吗?

{
  path: 'contents/:id',
  component: ContentComponent,
  children: [
     path: 'contents/:id',
     component: AnotherContentComponent,
  ]
}

问题在于这个“再次嵌套的子路由”:我不知道会有多少层级。它必须是递归的,但我不知道是否可能。 - Christian Benseler
@ChristianBenseler 在 angular2 中,嵌套路由由子组件处理。我不知道你所说的递归是什么意思。 - Ashot

0
路由有一个 children:[] 包含子路由。但是您需要为此设计您的应用程序才能实现您要寻找的内容:
{ path: 'contents/:id', component: ContentComponent, children:[
  {path:'child1', component:TheChild1Component, children:[ {nested child route}]},
  {path:'child2', component:TheChild2Component, children:[ { another nested child route}]}
   ...
] }

问题在于这个“再次嵌套的子路由”:我不知道会有多少层级。它必须是递归的,但我不知道是否可能。 - Christian Benseler

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接