Angular 2 routerlink with multiple routes?

后端 未结 2 870

I want to remove a class only one ONE route, (Or add a class on all BUT one route.) How is that possible? I have tried [routerLink] with multiple parameters to no avail:

2条回答
  •  时光说笑
    2021-01-20 06:06

    I don't know if there is a built in directive to do what you want but you can always add some logic to your component.

    In your template,

    And in your component,

    bodyContentClass() {
      // router  is an instance of Router, injected in the constructor
      return this.router.isActive('/url-to-make-body-active') || this.router.isActive('/other-url-to-make-body-active') ? 'col-sm-9' : '';
    }
    

    You can have fun and test against whatever combination of routes you wish.

提交回复
热议问题