[Vuejs]-Linking router-link and scrollBehavior not working โ€“ Vue 3 and Ionic 6

0๐Ÿ‘

โœ…

I was able to solve this by the answer from @Masoud Ehteshami to the similar question.

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
  scrollBehavior(to, from, SavedPosition) {
    if (to.hash) {
      const el = window.location.href.split("#")[1];
      if (el.length) {
        document.getElementById(el).scrollIntoView({ behavior: "smooth" });
      }
    } else if (SavedPosition) {
      return SavedPosition;
    } else {
      document.getElementById("app").scrollIntoView({ behavior: "smooth" });
    }
  },
});

Leave a comment