Vue-router: Vue router 1 anchor router.go named route

Created on 2 Nov 2016  路  6Comments  路  Source: vuejs/vue-router

I think it has been partially solved by https://github.com/vuejs/vue-router/issues/47 but I can't make it work with named routes

router.go('routename#withanchor') // works according to https://github.com/vuejs/vue-router/issues/47
router.go({name: 'routename'}) // how can I pass anchor ?

Anyone had this issue ?

Most helpful comment

router.go({name: 'routename', hash: 'anchor-here'})

All 6 comments

router.go({name: 'routename', hash: 'anchor-here'})

Already tried it (i'm on latest release for vue 1 i.e. 0.7.13)
Also tried the following but there is no hash in the generated href

<a v-link="{name: 'routename', hash: 'anchor'}">link</a>

Sample: http://codepen.io/lbineau/pen/aBopaz?editors=1010#0

Sorry, I thought you were using vue-router 2.0...
Using hash isn't supported in 0.7, please consider migrating to 2.0: http://vuejs.org/guide/migration-vue-router.html

Migrating to 2.0 is too heavy does not worth for this kind of problem. Is there a way to get the path from route object instead of going to the page (I could use it and append manually the hash) ?
Something like:

router.getPath({name: 'routename'})

Unfortunately that's also only available in 2.0 as router.match() (undocumented though..)

I reproduced the behavior of the anchor with query parameter ?hash=anchor thanks for you help !

Was this page helpful?
0 / 5 - 0 ratings