您好,我有父组件“订单”和两个子组件“历史记录”和“订单”。当前网址为 order/history/id
我想返回“订单”组件 like order/orders/id
所以我在我的应用程序中使用 Router。
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
解决这个问题的最佳方法是什么?谢谢。
最佳答案
当您在组件内使用导航时,您可以使用 ActivatedRoute
服务。
所以在你的历史组件中,尝试这样做:
constructor(
private route: ActivatedRoute,
private router: Router
) {}
navigateToOrders() {
this.router.navigate(['orders', orderId], { relativeTo: this.route.parent })
}
关于angular7 - Angular 6 如何返回父级然后在 router.navigate() 中返回子级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54885963/