0👍
This code has worked for me:
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes,
scrollBehavior(to, from, savedPosition) {
if (savedPosition) {
return savedPosition;
} else {
return {
el: to.hash,
behavior: "smooth",
};
}
},
});
Source:stackexchange.com