I'm using named outlets to show a sidebar. Works fine:
<a [routerLink]="['/', {outlets: {sidebar: 'profile'}}]">
Open sidebar
</a>
I also have a link which closes the sidebar. Also works fine:
<a [routerLink]="['/', {outlets: {sidebar: null}}]">
Close
</a>
Here's the problem. I want to have a third link, which links to a contacts route AND closes the sidebar. I tried doing this:
<a [routerLink]="['/contacts', {outlets: {sidebar: null}}]">
Contacts
</a>
But nothing happens when I click that third link.
How can I navigate to another route and simultaneously remove a named outlet?
Named outlet can be more than one per template. The component which needs to open in named outlet will configure its path with target outlet name in routing module using outlet property of Route interface. More than one named outlet can stay open together. Named outlet uses secondary routes to open a component.
Descriptionlink Using named outlets and secondary routes, you can target multiple outlets in the same RouterLink directive.
Yes you can as said by @tomer above. i want to add some point to @tomer answer. firstly you need to provide name to the router-outlet where you want to load the second routing view in your view. (aux routing angular2.)
The first property, path , defines the URL path for the route. The second property, component , defines the component Angular should use for the corresponding path.
It turns out, when closing a named outlet like this, you also have to specify what the primary outlet should be.
So the third link should look like this:
<a [routerLink]="['/', {outlets: {sidebar: null}, {primary: 'contacts'}}]">
Contacts
</a>
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