Vue-router: linkActiveClass isn't set on original link when visiting through alias

Created on 23 Mar 2016  路  11Comments  路  Source: vuejs/vue-router

Vue.js & vue-router.js version

2.5.17 & 3.0.1

Reproduction Link

https://jsfiddle.net/8xrk1n9f/1279/

Steps to reproduce

router.map({
    '/foo': {
        component: Foo
    },
    '/bar': {
        component: Bar
    }
})

router.alias({
    '/baz': '/bar'
})

What is Expected?

The /baz path is alias of /bar, it should be active when i click /baz link.

What is actually happening?

nothing happened, but route to component Bar

feature request fixed on 4.x improvement

Most helpful comment

I know it's probably not the most straightforward way to implement it but i have a workaround that might help some people here.

{
  {  
    path: '/',
    beforeEnter: (to, from, next) => next('/actual-route'),  
  },  
  {  
    path: '/actual-route',  
  },  
}

This wil redirect your alias to the intended route and setting the linkActivelass when visiting through an alias.

(source: https://github.com/vuejs/vue-router/issues/1191)

All 11 comments

Any progress on this?

This went under my radar for too long. I will take a look tomorrow

Forgot to give an update. The current mechanism to compare route doesn't properly take into account aliases as it should compare records. There is a workaround to do it in userland but this depends on #2286 being merged

There is a workaround to do it in userland

@posva you mind sharing some example/links ?

It depends on that PR to be merged first

Any progress?

I know it's probably not the most straightforward way to implement it but i have a workaround that might help some people here.

{
  {  
    path: '/',
    beforeEnter: (to, from, next) => next('/actual-route'),  
  },  
  {  
    path: '/actual-route',  
  },  
}

This wil redirect your alias to the intended route and setting the linkActivelass when visiting through an alias.

(source: https://github.com/vuejs/vue-router/issues/1191)

Any updates on the PR merge or other fix?

Not clear if the above comment means this is fixed? Just hit it today, really can't use the alias feature without correct link highlighting. When is 4.x planned for release?

Is there any update on planned date for 4.x release?

The release was one month ago.

https://github.com/vuejs/vue-router-next/releases/tag/v4.0.0

That's for Vue 3 though.

Was this page helpful?
0 / 5 - 0 ratings