vite-plugin-vue-layouts
vite-plugin-vue-layouts copied to clipboard
Scrolling to an element does not work
When using with vue-router, scrolling to an element via URL hash does not work:
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: setupLayouts([
{
path: "/",
name: "Home",
component: Home,
},
{
path: "/foo",
name: "Foo",
component: Home,
},
]),
scrollBehavior(to, from, savedPosition) {
if (to.hash) {
return {
el: to.hash,
};
}
if (savedPosition) {
return savedPosition;
}
return { top: 0 };
},
});
The console error is:
[Vue Router warn]: Couldn't find element using selector "#p0" returned by scrollBehavior.
Removing setupLayouts
fixes the issue.