Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I keep a navigation link highlighted on selection in Vue.js

So, I have a navigation bar with router-links. What I want is for the selected link to remain highlighted on selection, so that the users know which page they are on. Currently I have something like this.

<div class="mynav">
    <router-link to="...">...</router-link>
    ....
</div>

...

.mynav {
 ...
}

.mynav a {
 ...
}

.mynav a:hover {
 ...
}

I tried to use .mynav a:active, but that didn't work.

like image 218
MetallicPriest Avatar asked Nov 17 '25 09:11

MetallicPriest


1 Answers

Just add this style to the style tag inside the Vue component:

<style lang="css">
    .router-link-exact-active {
        border-bottom: 1px solid #123456;
    }
</style>
like image 175
Rodrigo Avatar answered Nov 19 '25 10:11

Rodrigo