Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RouterLink to navigate back in child route

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.

like image 487
Dawid Zbiński Avatar asked Sep 08 '16 15:09

Dawid Zbiński


People also ask

What is difference between routerLink and routerLink?

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.

What does routerLink directive do?

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.

What is relativeTo in Angular routing?

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.


1 Answers

I guess you wanted to redirect back to parent.

[routerLink]="['../../parent']"
like image 196
Pankaj Parkar Avatar answered Sep 23 '22 07:09

Pankaj Parkar