My AppComponent has a @RouteConfig decorator that defines the top-level routes:
@RouteConfig([
{
path: '/',
name: 'Home',
component: HomeComponent
},
{
path: '/about',
name: 'About',
component: AboutComponent
},
{
path: '/profile/...',
name: 'Profile',
component: ProfileComponent
}
])
export class AppComponent {
}
My ProfileComponent has a @RouteConfig decorator that defines the Profile child routes:
@RouteConfig([
{path: '/', component: ProfileDetailsComponent, name: 'View', useAsDefault: true},
{path: '/:id', component: ProfileDetailsComponent, name: 'Public'},
{path: '/edit', component: ProfileEditorComponent, name: 'Edit'},
])
export class ProfileComponent {
}
When i'm inside ProfileDetailsComponent I can do redirects to other Profile routes but not others. I want to avoid specifying the url using navigateByUrl and use route names instead, using navigate. E.g.:
this.router.navigate(['View']); // Works
this.router.navigate(['About']); // Raises error that it does not exist
I read this answer here: Angular 2 - How to navigate to another route using this.router.parent.navigate('/about')
It uses:
this.router.parent.navigate(['About']);
Which is sort of ok, but solves my problem only when I know at declaration time where the redirect should go. I have multiple levels of nesting and determine the target route at runtime. I'm looking for a way to do something like:
this.router.navigate(['Level1', 'Level2', 'Level3']);
Which allows me to track somewhere the fully qualified name of the target route. Is this possible in any way?