如何在 child 处于活动状态时使 parent 状态处于活动状态(即添加活动 class)

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 时,路由器 Link 被激活,但当我导航到 AlertComponent 时,它没有激活。

我想激活路由器 link。即使我导航到 AlertComponent

如何实现?

我的错。菜鸟的错误。更改为模块 URL 修复一切

<ul class="">
  <li class="">
    <a [routerLinkActive]="['active']"
       [routerLink]="['/user/traffic/']" class="">
       Traffic
    </a>
  </li>
</ul>