[Vuejs]-How to scroll to the element using scrollBehavior and hash in Vue

1👍

The only thing that you need in order to scroll top after each route change is to add this in router file

scrollBehavior(to, from, savedPosition){
  return{ left: 0, top: 0}
}

in case you want to go back and visit your last browser position you can do this:

scrollBehavior(to, from, savedPosition){
  if(savedPosition){
    return savedPosition
  }
  return{ left: 0, top: 0}
}

Leave a comment