Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular routerLinkActive with nested routes

I have problem. On my page, I have route /productsList. And I have list-group :

<div class="sticky-top">

  <ul class="list-group">
    <a  class="list-group-item list-group-item-action"  [routerLink]="['/productsList']"   routerLinkActive="active"  > sad</a>

    <a *ngFor="let products of categoryProduc; let i = index"  [routerLink]="[products.name]"  routerLinkActive="active"   class="list-group-item list-group-item-action">
      {{ products.name }}
    </a>
  </ul>

</div>

When I click on the some Item of list, route is changed example: /productsList/product and item is selected, but my :

<a  class="list-group-item list-group-item-action"  [routerLink]="['/productsList']"   routerLinkActive="active"  > sad</a>

Is always selected because I always have /productsList, I want when I have nested route to be disable.

like image 247
Kin Jong Avatar asked Oct 20 '25 14:10

Kin Jong


1 Answers

You have to define [routerLinkActiveOptions]="{ exact: true }" to make the difference between /productsList and /productsList/product:

<a class="list-group-item list-group-item-action" [routerLink]="['/productsList']" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: true }">not sad</a>
like image 115
Johan Rin Avatar answered Oct 23 '25 04:10

Johan Rin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!