How to set Bootstrap navbar “active” class in Angular 2?

后端 未结 11 696
被撕碎了的回忆
被撕碎了的回忆 2020-12-07 18:36

How can I set Bootstrap navbar \"active\" class in Angular 2? I only found Angular 1 way.

When I go to About page, add class=\"active\"

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 18:49

    Bert Deterd's answer is correct, but there's one thing that can be added.

    If one route is a substring of another route, you will see something like this happen: 2 active anchors

    You can add this to make it match exact routes only:

    [routerLinkActiveOptions]="{exact:true}"
    

    Full Example:

    
    

提交回复
热议问题