Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrolling to an element does not work #154

Open
vmihailenco opened this issue Jun 24, 2024 · 0 comments
Open

Scrolling to an element does not work #154

vmihailenco opened this issue Jun 24, 2024 · 0 comments

Comments

@vmihailenco
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant