本文介绍了子级处于活动状态时如何使父级状态处于活动状态(即添加活动类)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一些路线

<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>

这篇关于子级处于活动状态时如何使父级状态处于活动状态(即添加活动类)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 07:13