2

Hi I'm having parent component 'Order' and two child component for it 'History' and 'Orders'. Current url is order/history/id I want to go back to 'Orders' component like order/orders/id so I'm using Router in my app.

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

in history component as suggested in How do I navigate to a parent route from a child route? but it showing cannot match any routes url segment orders/7y6786 What is the best approach to solve this? Thank you.

e.k
  • 1,333
  • 1
  • 17
  • 36

1 Answers1

2

As you are using the navigate inside a component, you may use the ActivatedRoute service.

So in you History Component, try to do this:

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

navigateToOrders() {
  this.router.navigate(['orders', orderId], { relativeTo: this.route.parent })
}
Leandro Lima
  • 1,164
  • 6
  • 12