My goal is to achieve the same routing behavior on my website as demonstrated here: https://router.vuejs.org/guide/#html. If you observe, the link changes to https://router.vuejs.org/guide/#javascript when you scroll down, and reverts when scrolling back up. Additionally, the page retains your position even after reloading.
To implement a similar scroll behavior in my router, I have added the following code:
scrollBehavior(to, from, savedPosition) {
if (to.hash) {
return { selector: to.hash }
} else if (savedPosition) {
return savedPosition;
} else {
return { x: 0, y: 0 }
}
While I have managed to create links that direct to anchors and update the route accordingly, I am still puzzled on how to replicate the dynamic behavior observed on the Vue Router website. It's a bit ironic that I chose their site as an example, but nonetheless, any suggestions on achieving this level of functionality?