Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created August 17, 2018 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreasvirkus/1c97b36a00b157779caca80238e112aa to your computer and use it in GitHub Desktop.
Save andreasvirkus/1c97b36a00b157779caca80238e112aa to your computer and use it in GitHub Desktop.
Vue router middleware which keeps the scroll state of the former page
import VueRouter from 'vue-router'
export default new VueRouter({
scrollBehavior(to, from, savedPosition) {
if (to.hash) {
return { selector: to.hash }
}
return savedPosition || { x: 0, y: 0 }
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment