I have few routes in my application. Parent route admin
has few other child routes like posts, about-me, categories
. I want to be able to access the child route and navigate back if the user wants to. I was trying to add a link
<a class="pointer" [routerLink]="['admin']">Back</a>
but, the Router was just adding this link to ActivatedRoute (so the url looked like: http://localhost/admin/posts/admin).
So my question is what's the correct way to navigate back from the child route? Thank you in advance.
What is the difference between [routerLink] and routerLink ? How should you use each one? They're the same directive. You use the first one to pass a dynamic value, and the second one to pass a static path as a string.
Linking Routes in HTML To add links to one of the routes, use the routerLink directive in HTML. This directive accepts an array. The first parameter is the name of the route, and the second parameter is the parameters that you want to pass with the route.
We need to import ActivatedRoute and Router module from @angular/router . The object { relativeTo: this. router} ensures that the path remains relative to its parent path.
I guess you wanted to redirect back to parent.
[routerLink]="['../../parent']"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With