Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

routerLinkActive remain active even when other link is clicked

Tags:

angular

<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?

like image 432
vurrd Avatar asked Nov 02 '25 00:11

vurrd


1 Answers

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

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

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

like image 71
Günter Zöchbauer Avatar answered Nov 03 '25 16:11

Günter Zöchbauer



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!