How the route is changed, matters for my case. So, I want to catch when the route is changed by a back button of browser or gsm.
This is what I have:
This is done very easily.
const router = new VueRouter({
routes: [...],
scrollBehavior (to, from, savedPosition) {
if (savedPosition) {
// History back position, if user click Back button
return savedPosition
} else {
// Scroll to top of page if the user didn't press the back button
return { x: 0, y: 0 }
}
}
})
Check here: https://router.vuejs.org/guide/advanced/scroll-behavior.html#async-scrolling