Considering I'm on route
/parentOne/param1/param2/child
Is there any way for me to navigate to this another route, without passing the entire path (/param1/param2/child
)?
/parentTwo/param1/param2/child
The solution I have today:
const path = this.router.url.replace(regex, 'parentTwo');
this.router.navigate([path]);
The solution I wish I could implement:
this.router.navigate(['parentTwo', '...']);
Check out NavigationExtras. https://angular.io/api/router/NavigationExtras Using relativeTo and relative path, you can navigate
go() {
this.router.navigate(['../list'], { relativeTo: this.route });
}
Example:
const appRoutes = [
{
path: 'p1', component: P1,
children: [
{
path: ':id',
component: P1C
}
]
},
{
path: 'p2', component: P2,
children: [
{
path: ':id',
component: P2C
}
]
},
];
this.r.navigate(['../../p1', '2'], {relativeTo: this.a})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With