gpt4 book ai didi

Angular 5 导航

转载 作者:太空狗 更新时间:2023-10-29 17:39:02 26 4
gpt4 key购买 nike

考虑到我在路上

/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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com