问题
I'm playing around with the named outlets and I noticed that the following code works, sending me to the requested page but only if it's outside another outlet.
<div routerLink="banana">Working Banana</div>
When the above code is part of the markup rendered inside the primary outlet, the routing occurs as supposed to. However, the same routing request done from a component that's rendered in one of the named outlets seems not to work at all.
I'm reluctant to call a bug on stuff that smarter people have done, so I'm assuming there is a way to route in the primary outlet when clicking a component rendered in a named outlet. But how?
For the demo of working and not working bananas see here at StackBlitz. And yes, I've googled. But it's not exactly easy to find a good key combo for this stuff...
回答1:
The problem is that routerLink="banana"
performs navigation relative to the current route. While it seems that you want to navigate to domain.com/banana
and for that you need an absolute navigation. To make it absolution navigation just add a forward slash:
<div routerLink="/banana">
来源:https://stackoverflow.com/questions/45765264/cant-route-to-the-primary-outlet-from-component-rendered-in-a-named-outlet-in-a