Displaying active navigation based on contextual data

后端 未结 6 1188
礼貌的吻别
礼貌的吻别 2021-02-07 00:36

I have the following separated fragment in a Thymeleaf template.

6条回答
  •  星月不相逢
    2021-02-07 00:55

    while this is an old question, I want to share this solution as it could be much more elegant!

    http://nixmash.com/post/bootstrap-navbar-highlighting-in-thymeleaf

    • Add a parameter (activeTab) to the navigation fragment.
    • pass the value of it in the main pages that use the navbar fragment
     
    • check for it in 'li' element to set the 'active' class
     
  • About
提交回复
热议问题