A
A
Alexander Osadchy2021-08-05 00:08:13
Angular
Alexander Osadchy, 2021-08-05 00:08:13

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>


The output link is:
http://localhost:4200/events/1000?pageSize=10&pageNumber=1&radius=100&dateRange=0&fromDateTimeUtc=2021-08-05


Or here's the paragraph:
<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>


The output link is this:
http://localhost:4200/travel-search?tab=hotels

Here I found routeToDest
routeToDest(dest, extras = {}) {
    this.router.onSameUrlNavigation = 'reload';
    this.router.navigate([dest], extras);
  }


How to add the 'is-active' class to such links if the page is active?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question