I have a bootstrap 4 navbar that includes a dropdown menu with routes. I am able to show the active route based on 'routerLinkActive', but I also want to style the 'dropdown-toggle' or 'nav-item' as active when one of its child elements is the active route.
How can I achieve this?
Below is a refined snippet of the code for readability:
<li *ngFor="let menuItem of MenuItems; index as i" [id]="i" class="nav-item dropdown" ngbDropdown>
<a class="nav-link dropdown-toggle" ngbDropdownToggle>
{{menuItem.title}}
</a>
<!-- dropdown menu -->
<div *ngIf="menuItem.submenu.length > 0" class="dropdown-menu" ngbDropdownMenu aria-labelledby="i">
<div *ngFor="let menuSubItem of menuItem.submenu">
<a [routerLink]="menuSubItem.path"
[routerLinkActive]="['active-sub']" <== ** this part works and sets the class, now i need the top nav-link to be active too
[routerLinkActiveOptions]="{exact: true}"
class="dropdown-item">
{{menuSubItem.title}}
</a>
</div>
</div>
</li>