加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular 5导航

发布时间:2020-12-17 18:11:16 所属栏目:安全 来源:网络整理
导读:考虑到我在路上 /parentOne/param1/param2/child 有没有办法让我导航到另一条路线,而不通过整个路径(/ param1 / param2 / child)? /parentTwo/param1/param2/child 我今天的解决方案: const path = this.router.url.replace(regex,'parentTwo');this.route
考虑到我在路上

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读