Angular 2 routerLinkActive always active for base path

Discussão em 'Angular' iniciado por gempir, Janeiro 26, 2025.

  1. gempir

    gempir Guest

    I have this code for my navbar:

    <nav>
    <a [routerLink]="['/']" [routerLinkActive]="['nav-active']">HOME</a>
    <a [routerLink]="['/about']" [routerLinkActive]="['nav-active']">ABOUT</a>
    <a [routerLink]="['/records']" [routerLinkActive]="['nav-active']">RECORDS</a>
    </nav>


    The problem is the HOME nav point always gets the class because / seems to be always active. Is this avoidable with a small and simple solution?

    Thanks for the help

    Edit:

    this is the solution for now:

    [routerLinkActiveOptions]="{ exact: true }"

    Continue reading...

Compartilhe esta Página