Can't route to the primary outlet from component rendered in a named outlet in Angular

北慕城南 提交于 2019-12-11 04:13:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!