Angular 6 我怎样才能回到父级然后在 router.navigate() 中回到子级
Angular 6 how can I go back to parent then come to child in router.navigate()
您好,我有父组件 'Order' 和两个子组件 'History' 和 'Orders'。当前 url 是 order/history/id
我想返回 'Orders' 组件 like order/orders/id
所以我在我的应用程序中使用路由器。
this.router.navigate(['../../orders', orderId]);
在 中建议的历史组件中,但它显示 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 })
}
您好,我有父组件 'Order' 和两个子组件 'History' 和 'Orders'。当前 url 是 order/history/id
我想返回 'Orders' 组件 like order/orders/id
所以我在我的应用程序中使用路由器。
this.router.navigate(['../../orders', orderId]);
在 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 })
}