简体   繁体   English

角2路由:空的routerLink不起作用

[英]Angular 2 routing: empty routerLink does not work

I'm configuring my routing and stumbled on this issue. 我正在配置我的路由,但偶然发现了这个问题。

I currently have these 2 routes: 我目前有以下2条路线:

const appRoutes: Routes = [
    { path: '', component: HomeComponent },
    { path: 'products', component: ProductComponent}
];

Am I not allowed to define an empty route? 我是否可以定义空路径? Because the code below is not working 因为下面的代码不起作用

<a routerlink="">Home</a>

What is working, is the other route products : 起作用的是其他路线products

<a routerLink="products">Products</a>

I searched the internet but did not yet found a solution. 我搜索了互联网,但尚未找到解决方案。 Since I want to keep my url clean, I can't use the redirectTo option to redirect to eg a home path. 由于我想保持URL干净,因此无法使用redirectTo选项重定向到例如home路径。 I want my home url to be www.example.com and not www.example.com/home . 我希望我的家庭网址是www.example.com而不是www.example.com/home

I hope you guys understand my question. 我希望你们能理解我的问题。

OK, I see what I did wrong. 好,我知道我做错了。

It was a typo: I used routerlink instead of routerLink in my HTML. 这是一个错字:我在HTML中使用了routerlink而不是routerLink So an empty routerLink does work with Angular 2 RC6. 因此,空的routerLink可以与Angular 2 RC6一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM