[Vuejs]-Vue 3 options api, how to scroll to an anchor via ID

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",
      };
    }
  },
});

Vue router Info

Leave a comment