问题
I current have some routes
<ul class="">
<li class="">
<a [routerLinkActive]="['active']"
[routerLink]="['/user/traffic/graph']" class="">
Traffic
</a>
</li>
</ul>
Routes
const trafficRoutes: Routes = [
{
path: '', component: TrafficComponent, children: [
{ path: '', redirectTo: 'graph' },
{ path: 'graph', component: GraphComponent},
{ path: 'alerts', component: AlertComponent}
]
},
];
The Router Link gets activated when I navigate to GraphComponent
but when I navigate to AlertComponent
it is not active.
I want to make that router link active. Even when I navigate to AlertComponent
How to achieve that?
回答1:
My bad. A Rookie Mistake. Changing to the module URL fixes everything
<ul class="">
<li class="">
<a [routerLinkActive]="['active']"
[routerLink]="['/user/traffic/']" class="">
Traffic
</a>
</li>
</ul>
来源:https://stackoverflow.com/questions/46447371/how-to-make-parent-state-activei-e-add-active-class-when-child-is-active