简体   繁体   中英

Angular 2 routing: empty routerLink does not work

I'm configuring my routing and stumbled on this issue.

I currently have these 2 routes:

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 :

<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. I want my home url to be www.example.com and not 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. So an empty routerLink does work with Angular 2 RC6.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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