当孩子处于活动状态时如何使父状态处于活动状态(即添加活动类) [英] how to make parent state active(i.e., add active class) when child is active
本文介绍了当孩子处于活动状态时如何使父状态处于活动状态(即添加活动类)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有一些路线
<ul class="">
<li class="">
<a [routerLinkActive]="['active']"
[routerLink]="['/user/traffic/graph']" class="">
Traffic
</a>
</li>
</ul>
路线
const trafficRoutes: Routes = [
{
path: '', component: TrafficComponent, children: [
{ path: '', redirectTo: 'graph' },
{ path: 'graph', component: GraphComponent},
{ path: 'alerts', component: AlertComponent}
]
},
];
当我导航到 GraphComponent
时,路由器链接被激活,但当我导航到 AlertComponent
时,它未激活.
The Router Link gets activated when I navigate to GraphComponent
but when I navigate to AlertComponent
it is not active.
我想让该路由器链接处于活动状态.即使我导航到 AlertComponent
I want to make that router link active. Even when I navigate to AlertComponent
如何实现?
推荐答案
我的错.菜鸟错误.更改为模块 URL 可以解决所有问题
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>
这篇关于当孩子处于活动状态时如何使父状态处于活动状态(即添加活动类)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文