【问题标题】:Angular 6 how can I go back to parent then come to child in router.navigate()Angular 6我怎样才能回到父母,然后在router.navigate()中找到孩子
【发布时间】:2019-02-26 12:50:17
【问题描述】:

您好,我有父组件“订单”和两个子组件“历史”和“订单”。当前 url 是 order/history/id 我想回到“订单”组件 like order/orders/id 所以我在我的应用程序中使用路由器。

this.router.navigate(['../../orders', orderId]); 

How do I navigate to a parent route from a child route? 中建议的历史组件中,但它显示cannot match any routes url segment orders/7y6786 解决此问题的最佳方法是什么?谢谢。

【问题讨论】:

  • 改用navigateByUrl

标签: angular7 angular-router


【解决方案1】:

当您在组件内使用导航时,您可以使用ActivatedRoute 服务。

所以在你的历史组件中,尝试这样做:

constructor(
  private route: ActivatedRoute,
  private router: Router
) {}

navigateToOrders() {
  this.router.navigate(['orders', orderId], { relativeTo: this.route.parent })
}

【讨论】:

    猜你喜欢
    • 2017-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-27
    • 2021-06-15
    • 1970-01-01
    • 2017-07-01
    • 2013-03-01
    相关资源
    最近更新 更多