Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support hash parameter in v-link and improve custom handling #434

Closed
noirbizarre opened this issue Mar 29, 2016 · 2 comments
Closed

Support hash parameter in v-link and improve custom handling #434

noirbizarre opened this issue Mar 29, 2016 · 2 comments
Labels

Comments

@noirbizarre
Copy link

It would be nice to be able to use hash with named route pattern.

Currently

In vue-router 0.7.11, in History/html5 mode:

  • hash is automatically extracted from path given as string and scroll to this hash after route change
    (ie. v-link="/page#section" will to to the route /page and scroll to the element with this id (https://github.com/vuejs/vue-router/blob/master/src/index.js#L543-L560)
  • there is no way to specify an anchor/a hash with the named route pattern (ie. v-link="{name: 'page', params: {}}")

Proposal

  • Add/handle an optional hash or anchor in v-link named route pattern handling (ie. v-link="{name: 'page', hash: 'section'}")
  • Add a, optional hash() transition hook called after data hook, if hash value change (same behavior as data hook for hash) :
Vue.component('hash-hook-example', {
  // ... other options
  route: {
    hash (value) {
      console.log(`hash-hook triggered with ${value}`)
    }
  }
})

If the hook is present, it is called. If not, the default behavior (aka. scroll to getElementById(hash)) is executed

@divmgl
Copy link

divmgl commented Jul 29, 2016

+1 on this, would really like to see links that are create by Vue and can scroll to an anchor

@fnlctrl
Copy link
Member

fnlctrl commented Aug 28, 2016

@noirbizarre @divmgl Scrolling to hash is implemented in 2.0, as in scrollBehavior (release notes),

As for hash hook, since all transition hooks are deprecated in 2.0, there won't be any new hooks added, so you can just use a watcher on $route.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants