Brian B
Brian B

Reputation: 310

Angular :: Link to parent 'router-outlet' from a nested outlet

I have a component within a nested router-outlet, but would like to create a link to a route that is in the parent's router-outlet. I am not sure what code you guys would want to see for me to explain this?

Upvotes: 3

Views: 850

Answers (2)

Brian B
Brian B

Reputation: 310

I was not able to do it from the template (maybe seeing this answer someone could show me the way to do it from the template), but I was able to make it work by navigating programmatically like this:

this.router.navigate(['../../account-view/' + id], { relativeTo: this.route.parent });

Upvotes: 2

Yaser
Yaser

Reputation: 5719

You can point to anywhere in your app with routerLink regardless of where you are. It is just the matter of how you set the route. If you start the route with / it means from base (don't forget to set the base in your HTML).

If you use ./ it is relative to where you are.

So let's assume you have two main routes, admin and frontpages, which have their own modules. Inside admin there is a users route and inside frontpage there is about route. You can have a link to admin from about like this:

<a routerLink="/admin/users">Admin</a>

I created this stackblitz for you to checkout.

Upvotes: 0

Related Questions