简体   繁体   中英

Angular: get absolute path with routerLink

I'm working on a navigation button bar where the current route toggle a css-class (footer-btn-active) which "lights" up the button of the current route.

This is the current code:

<button routerLink="/system"
                routerLinkActive="footer-btn-active"
                class="footer-btn">System-info</button>

how it works now: The button class (footer-btn-active) stays active, on every path of /system/...

how it should work: I want that the button class (footer-btn-active) stays active, only on the absolute path /system

try with below property, exact: true will only make class active if exact path matches.

<button 
routerLink="/system"
routerLinkActive="footer-btn-active"
[routerLinkActiveOptions]="{ exact: true }"
class="footer-btn">System-info</button>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM