考虑到我在路上
/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和relative路径,您可以导航
https://angular.io/api/router/NavigationExtras
使用relativeTo和relative路径,您可以导航
go() { this.router.navigate(['../list'],{ relativeTo: this.route }); }
例:
const appRoutes = [ { path: 'p1',component: P1,children: [ { path: ':id',component: P1C } ] },{ path: 'p2',component: P2,component: P2C } ] },]; this.r.navigate(['../../p1','2'],{relativeTo: this.a})