Answer the question
In order to leave comments, you need to log in
How to add active link class without routerLink?
Hello!
There is a menu whose items do not contain a routerLink , and how can I add a class for the active menu item in this case?
For example, here is the paragraph:
<a class="col text-center categories-menu-item" [routerLinkActive]="['is-active']" [routerLinkActiveOptions]="{exact:
true}">
<span (click)="routeToDest('events/1000')">Sports</span>
<app-category-dropdown-list class="top-level-category"
[categories]="navbarMenuItems[0]?.children"
(onEntertainerSelected)="onEntertainerClicked($event)"
(onNCAASelected)="onNCAAClicked($event)"
[isFirstLevel]="true"
(onCategorySelected)="onCategorySelected($event)"></app-category-dropdown-list>
</a>
http://localhost:4200/events/1000?pageSize=10&pageNumber=1&radius=100&dateRange=0&fromDateTimeUtc=2021-08-05
<a class="col text-center categories-menu-item" routerLinkActive="is-active">
<span (click)="routeToDest('travel-search', { queryParams: {tab: 'hotels'}})">Travel</span>
<app-category-dropdown-list class="top-level-category"
[categories]="travelCategories"
[isFirstLevel]="true"
(onCategorySelected)="onCategorySelected($event)"></app-category-dropdown-list>
</a>
http://localhost:4200/travel-search?tab=hotels
routeToDest(dest, extras = {}) {
this.router.onSameUrlNavigation = 'reload';
this.router.navigate([dest], extras);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question