I am using angular2 router.
To draw the breadcrumb of an url, lets say site.com/a/b/c/15 I do the following:
- Get the route of
site.com/a/b/c/15
and get the pretty name associated to the route
- Get the route of
site.com/a/b/c
and get the pretty name associated to the route
- Get the route of
site.com/a/b
and get the pretty name associated to the route
- Get the route of
site.com/a
and get the pretty name associated to the route
So lets say I do have the following routes:
{ path: 'a', component: A, data:{prettyName: 'I am A'}}
{ path: 'b', component: B, data:{prettyName: 'I am B'}},
{ path: 'c', component: C, data:{prettyName: 'I am C'}},
The result of my process would be an array containing {"I am C", "I am B", "I am C"}
and thanks to that I can display a nice breadcrumb "I am A > I am B > I am C"
that explains the current route.
This use to work with the router-deprecated doing
this.router.recognize(url).then((instruction) => {
instruction.component.routeData.get('prettyName') // Would return 'I am ..'
However now; with the last router I am not able to process this recognize logic anymore.
How to get the route data associated to an url ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…