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

Sibiraj

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?

Sibiraj

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>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Add class to parent only when child has an active class

Add class "item_active" to parent LI when a child LI has "item_active"

add class to parent li when submenu is active

How to ignore child element active region when parent:active is enable?

Change parent div to active when child is active

How can I show the active state of a child by clicking it's parent?

Add active class to child element

How to get active class on parent route link when visiting any child route?

How to make parent div activate styling of child div for hover and active

How to add class when active menu - jquery

How to add active state to tabs

How to add active class/state for li element in ReactJS?

How to add an active class to only one parent element with Jquery?

How can I have an abstract parent state know which child state is active?

Make active class for parent and subs in Laravel

Add active class based on child <a> href

AngulaJS add a class to parent for active radiobutton

Add class to parent li if NavLink is active

jQuery - add navigation active class on parent

How to apply style to child of element with active state

Make Angular router parent not active when it children are active

How to add class active in sequence?

how to add active class in xslt?

How to add and remove active class?

How to add an active class for a Navbar?

how to add class 'active' with jquery

How to add active class in django?

How to add "Active" class when input field is not empty

Automatically cast an active record child class on initialisation in its parent class