Angular 5导航

前端之家收集整理的这篇文章主要介绍了Angular 5导航前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
考虑到我在路上

/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路径,您可以导航

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})

猜你在找的Angularjs相关文章