For a project, we have routes that live in states. We wanted to navigate to a route relative to the current route. for each child route, we will be able to navigate to the previous and next route.
System context
Let’s say we have a app-routing.module.ts
with the following routes:
|
|
Router.navigate
We do not want to edit the url property, because it can lead to complexity. You would just say Angular does have the router to do so. The current route is a chain of activated routes when you are navigating to url like /parent/child1/child2/child3
.
|
|
To get the activated route for for example child3
when the url is /parent/child1/child2/child3
we need to get the last child route in the chain. This ActivatedRoute
object is passed to the relativeTo
property of the router.navigate
method.
|
|
Conclusion and discussion
This way we can navigate to a route relative to the current route. This is useful when you have a wizard-like flow in your application.