2016-12-24 54 views
0

我有2种途径Angular2选择2路与routerLinkActive

{ path: '', component: DefaultComponent }, 
{ path: 'second', component: SecondComponent } 

,而在HTML

<a [routerLink]="['/']" [routerLinkActive]="['active']">default</a> 
<a [routerLink]="['/second']" [routerLinkActive]="['active']">second</a> 

当我浏览到第二个他们两个有活跃的类。 这是一个错误或想

使用:

"@angular/router": "~3.3.0", 

回答

1

你可以达到你所期望的,当你添加pathMatch: 'full'到您的路线配置:

{ path: '', component: DefaultComponent, pathMatch: 'full' }, 
{ path: 'second', component: SecondComponent } 

然后第一条路只会激活如果完整的路径是匹配的,不仅如果路径的一部分是匹配的。

请参见:Routing & Navigation