问题描述
我对 angular 2 (RC1) 路由器有严重的问题.
i have serious problem with angular 2 (RC1) router.
此代码有效:
<a [routerLink]="['/anythingEvenNotExistingRoute']"></a>
<router-outlet></router-outlet>
这不会:
//<a [routerLink]="['/anything']"></a> <-- without this line in html template
<router-outlet></router-outlet>
...所以看起来角度路由器需要在 html 模板中至少有一个 routerLink .. 那很奇怪..
...so it looks like angular router needs atleast one routerLink in html template.. thats pretty strange..
推荐答案
这是当前 Angular 2 RC 路由器中存在的错误 https://github.com/angular/angular/issues/8409.
This is currently a bug present in the Angular 2 RC Router https://github.com/angular/angular/issues/8409.
正如在 GitHub 问题中提到的,要解决这个问题,您可以将路由器注入 AppComponent
或只放置一个空的路由器链接 (<a [routerLink]="['/']"></a>
) 到您的模板中.
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.
这篇关于Angular 2 RC1 路由器在没有任何 routerLInk 的情况下无法工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!