how to make parent state active(i.e., add active class) when child is active

纵然是瞬间 提交于 2019-12-23 18:48:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!