Currently, I am developing a website using Vue and Vue Router for routing. The method I am using to manage scroll behavior for anchor links is as follows:
const router = new VueRouter({
routes,
scrollBehavior (to) {
if (to.hash) {
return {
selector: to.hash,
offset: { x: 0, y: 140 }
}
}
return { x: 0, y: 0 }
}
})
My anchor links are created like this:
<router-link class="insurance-link d-block" to="#hogar">
<img class="insurance-logo img-fluid" src="@/assets/home-icon.svg">
Hogar
</router-link>
When I click on the link for the first time, it scrolls to the anchor position correctly. However, when I scroll back to the top and click on it again, it does not scroll back to that position. Interestingly, if I click on another anchor link and then click on the previous one, everything works as expected. Any insights on what might be causing this issue?