vurrd
vurrd

Reputation: 43

routerLinkActive remain active even when other link is clicked

<ul>
 <li routerLinkActive="active"><a routerLink="/">One</a></li>
 <li routerLinkActive="active"><a routerLink="/somewhere">Two</a></li>
</ul>

The problem with is, that when the Two link is clicked, the active class applied to both links - the One link remain highlighted... Why is this happening, please?

Upvotes: 4

Views: 1336

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657308

Add [routerLinkActiveOptions]="{exact: true}"

<li routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}">

See also https://angular.io/docs/ts/latest/api/router/index/RouterLinkActive-directive.html

Upvotes: 5

Related Questions