Angular - Apply style to element depending on sibling RouterLinkActive?

前端 未结 5 1885
栀梦
栀梦 2021-02-20 15:44

I do not have only one menu bar on my app that I need to be painted when the user navigates, I have another components too that needs to be painted as well. Can I achieve this j

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-20 16:17

    If you're main navigation item merely serves as a open/close mechanism for the submenu, but you still want to use the routerLinkActive mechanism built in to Angular, you can 'dupe' the parent item to thinking it's actually a routerLink. Like this:

    The trick is in the 'hidden' < span > element with the parent link. This will make sure the parent link is also highlighted with the routerLinkActive property on the parent element.

提交回复
热议问题