I've recently implemented a delay in my router configuration on my website. However, I've noticed that when I try to navigate using the browser's back and forward buttons, it first jumps to the top of the page because of the delay set with { left:0, top:0 }
. Is there a way to prevent this jump to the top during transitions triggered by the browser buttons, while still maintaining the behavior for other types of clicks, such as when using a router-link
?
export const router = createRouter({
history: createWebHistory(),
routes,
scrollBehavior(to, from, savedPosition) {
if (savedPosition || to.query.page) {
return savedPosition;
} else {
return new Promise(resolve => {
setTimeout(() => {
resolve({ left: 0, top: 0 });
}, 400);
});
}
},
});
If anyone has a solution or suggestion, please let me know. Thank you!