考虑到我在路上
/parentOne/param1/param2/child
有什么方法可以让我导航到另一条路线,而无需通过整个路径 (/param1/param2/child
)?
/parentTwo/param1/param2/child
我今天的解决方案:
const path = this.router.url.replace(regex, 'parentTwo');
this.router.navigate([path]);
我希望我可以实现的解决方案:
this.router.navigate(['parentTwo', '...']);
最佳答案
查看 NavigationExtras。 https://angular.io/api/router/NavigationExtras 使用 relativeTo 和相对路径,你可以导航
go() {
this.router.navigate(['../list'], { relativeTo: this.route });
}
例子:
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})
关于Angular 5 导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50161833/