Angular 2 RC1 Router doesn't work without any routerLInk

大兔子大兔子 提交于 2019-11-27 08:07:05

问题


i have serious problem with angular 2 (RC1) router.

This code works:

<a [routerLink]="['/anythingEvenNotExistingRoute']"></a>
<router-outlet></router-outlet>

This doesn't:

//<a [routerLink]="['/anything']"></a>  <-- without this line in html template
<router-outlet></router-outlet>

...so it looks like angular router needs atleast one routerLink in html template.. thats pretty strange..


回答1:


This is currently a bug present in the Angular 2 RC Router https://github.com/angular/angular/issues/8409.

As mentioned in the GitHub issue, to get around it you can either inject the router into AppComponent or just put an empty router link (<a [routerLink]="['/']"></a>) into your template.



来源:https://stackoverflow.com/questions/37310539/angular-2-rc1-router-doesnt-work-without-any-routerlink

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