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

有角度 – 如何导航到兄弟路线?

发布时间:2020-12-17 07:49:57 所属栏目:安全 来源:网络整理
导读:我们假设我有这个路由器配置 export const EmployeeRoutes = [ { path: 'sales',component: SalesComponent },{ path: 'contacts',component: ContactsComponent }]; 并通过此URL导航到SalesComponent /department/7/employees/45/sales 现在我想去联系人,但
我们假设我有这个路由器配置
export const EmployeeRoutes = [
   { path: 'sales',component: SalesComponent },{ path: 'contacts',component: ContactsComponent }
];

并通过此URL导航到SalesComponent

/department/7/employees/45/sales

现在我想去联系人,但是由于我没有绝对路线的所有参数(例如上面的例子中的部门ID,7),我更喜欢使用相对链接到达那里.

[routerLink]="['../contacts']"

要么

this.router.navigate('../contacts')

不幸的是不行.可能有一个明显的解决方案,但我没有看到.有人可以帮忙吗

如果您正在使用新的路由器(3.0.0-beta2),您可以使用ActivatedRoute导航到相对路径,如下所示:
constructor(private router: Router,private r:ActivatedRoute) {} 

///
goToContact() {
  this.router.navigate(["../contacts"],{ relativeTo: this.r });
}

(编辑:李大同)

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

    推荐文章
      热点阅读