0

I created a simple vue app with router. I managed to get the tab highlighted upon hovering on it but I want it to stay coloured until the user changes for another. Here is relevant code:

<nav>
    <ul>
    <li><router-link to="/contact">Contact</router-link></li>
    <li><router-link to="/blog">Blog</router-link></li>
    <li><router-link to="/ceremonies">Ceremonies</router-link></li>
    <li><router-link to="/pregnancy">Pregnancy Yoga</router-link></li>
    <li><router-link to="/about">About</router-link></li>
    <li><router-link to="/">Home</router-link></li>
    


    </ul>
  </nav>
ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color:#F1D0E5
}

li {
  float: right;
}

li a {
  font-size: 20px;
  display: block;
  color: #89a864;
  font-weight:900;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

li a:hover {
  background-color:#985277;
}
li a:active {
    background-color:#985277;

}

it does not stay higlighted as soon as I remove the cursor

kelbal
  • 3
  • 3
  • 1
    apply a class that styles the active tab. [bind the class](https://vuejs.org/guide/essentials/class-and-style.html#binding-html-classes) based on the current route which you can determine using the global `$route` object. – yoduh Dec 14 '22 at 19:52

1 Answers1

0

vue-router automatically adds two classes to the active <router-link> component.

.router-link-active and .router-link-exact-active

You can use those classes to style your links.

This is a comprehensive answer that covers how/when these classes are applied.

Nikola Gava
  • 306
  • 2
  • 6