vite-plugin-vue-layouts icon indicating copy to clipboard operation
vite-plugin-vue-layouts copied to clipboard

Scrolling to an element does not work

Open vmihailenco opened this issue 8 months ago • 0 comments

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.

vmihailenco avatar Jun 24 '24 07:06 vmihailenco