I have an app that has a base router-outlet that is used as a base for the entire app. then a child router-outlet that is used once a user is logged in to display any components loaded as a result of clicking on a navigation link clicked that is based in the base router-outlet. I want to be able to target the child router-outlet when a navigation link is clicked in the base template.
When I click on a nav item in the base template, it loads the component in the base router-outlet. That makes good sense to me. I would like to know how I can click a nav item in the base template and have the desired component load in the child router outlet.
I can't find any information on targeting a named router-outlet like I could do in RC4 (I think it was RC4) when i used to be able to do something like:
[routerLink]="/childroute#secureRouterOutlet"
Here is a really simple plunker that mimics how things are currently setup: plunkr
Please try write like this, hope it helps.
You can achieve that by enabling nested routes, you will need to setup
children
property onRoutes
. Here is the doc.Here is how it can be done, specific to your use case from plunkr.
On
src/app.ts
specify any components you want to add as children in yourRoutes
configuration. For example, addingChild2Component
as nested routes onChildComponent
will be like belowOn the navigation, you will need to add the link to
Child2Component
as belowNow, when you hit that link,
ChildComponent
will renderChild2Component
template insiderouter-outlet
inChildComponent
Here is working plunkr