Issue
I would like to know if it is possible to dynamically append child routes at run time, from lets say a service...?
Given:
const routes: Routes = [
{
path: '', component: GloriousComponent,
children: [
{ path: 'path1', component: Child1Component },
{ path: 'path2', component: Child2Component },
{ path: 'path3', component: Child3Component },
]
}
];
Could I remove the children of the ' ' path and somehow get a reference to the const routes and then later on dynamically append children to the ' ' path?
Something along the lines of...
const routes: Routes = [
{
path: '', component: GloriousComponent
}
];
routes[''].appendChildren(
[
{ path: 'path1', component: Child1Component },
{ path: 'path2', component: Child2Component },
{ path: 'path3', component: Child3Component },
]
)
Solution
Currently modifying is not supported but you can maintain a list of routes yourself and then call
this.router.resetConfig(routes)
to load a new set of routes into the router.
Answered By - Günter Zöchbauer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.