Giter Site home page Giter Site logo

Comments (14)

yyx990803 avatar yyx990803 commented on May 11, 2024 12

0e11456

For ease of use: the active link will automatically get .v-link-active. This class name can be configured as an option when creating the router as linkActiveClass.

from vue-router.

fnlctrl avatar fnlctrl commented on May 11, 2024 5

@amirrustam FYI in 2.0 there's exact matching mode: http://router.vuejs.org/en/api/router-link.html

from vue-router.

yyx990803 avatar yyx990803 commented on May 11, 2024 1

Ah, actually, we can just add an additional auto class: .v-link-child-active...

Or, maybe a partial match should be the default, where exact match adds the class .v-link-active-exact

from vue-router.

azamat-sharapov avatar azamat-sharapov commented on May 11, 2024

I was doing like v-class="active: route.path=='/page'" :) but helper would make it elegant probably. Also, something like route.componentName would be useful, i find myself doing route.path.split('/')[n] many times to find out which sub-route is currently active. What do you think?

from vue-router.

manudurgoni avatar manudurgoni commented on May 11, 2024

@azamat-sharapov 👍

from vue-router.

azamat-sharapov avatar azamat-sharapov commented on May 11, 2024

Oh yeah, now that's really Evan. 👍

from vue-router.

JosephSilber avatar JosephSilber commented on May 11, 2024

Would it make sense to have an option to also have the class present of a child route is active?

For example, if I have a 'users' link in my nav, I might want that to also be highlighted when I'm on 'users/:id' or 'users/create'.

from vue-router.

yyx990803 avatar yyx990803 commented on May 11, 2024

@JosephSilber I'll think about that, but it would introduce additional api surface to configure this behavior. In those cases it's probably better to do something csutom like v-class="active: /^user/.test(route.path)", or even a custom directive.

from vue-router.

manudurgoni avatar manudurgoni commented on May 11, 2024

Have you any idea why the classes do not apply on the app first init ?

Then when I navigate it updates itself!

from vue-router.

yyx990803 avatar yyx990803 commented on May 11, 2024

@manudurgoni not sure, it seems to be working correctly in the example (on initial load with a matched url).

from vue-router.

manudurgoni avatar manudurgoni commented on May 11, 2024

@yyx990803 You've right :)

On initial load, my route path is : fr/categorie/slug, so it doesn't match with the destination who is : /fr/categorie/slug. And when I navigate, all is good. I just need to find why the first slash is removed on init.

EDIT : ok I fixed my code :)

from vue-router.

amirrustam avatar amirrustam commented on May 11, 2024

@yyx990803 Any plans to include something like the .v-link-active-exact you proposed earlier?

from vue-router.

amirrustam avatar amirrustam commented on May 11, 2024

@fnlctrl 🙏 Thank you. I read right passed that when reading the docs.

from vue-router.

l2aelba avatar l2aelba commented on May 11, 2024

As 2.5.0+, Now just :
<router-link to="/" exact-active-class="is-active">Home</router-link>

Thanks @fnlctrl

from vue-router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.