我想知道是否可以在运行时动态地添加子路由,比如说服务...?
鉴于:
const routes: Routes = [
{
path: '', component: GloriousComponent,
children: [
{ path: 'path1', component: Child1Component },
{ path: 'path2', component: Child2Component },
{ path: 'path3', component: Child3Component },
]
}
];
我可以删除''路径的子代,然后以某种方式获取对const路由的引用,然后再动态地将子代添加到''路径吗?
类似于...
const routes: Routes = [
{
path: '', component: GloriousComponent
}
];
routes[''].appendChildren(
[
{ path: 'path1', component: Child1Component },
{ path: 'path2', component: Child2Component },
{ path: 'path3', component: Child3Component },
]
)
最佳答案
当前不支持修改,但是您可以自己维护路由列表,然后致电
this.router.resetConfig(routes)
将一组新的路由加载到路由器中。