search

Home  >  Q&A  >  body text

Strange jumps in scrolling behavior in Nuxt 3

So I configured the rouse.scrollBehaviour.ts file in Nuxt 3. as follows:

import { defineNuxtPlugin } from "#app";

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.$router.options.scrollBehavior = (to, from, savedPosition) => {
    if (savedPosition) {
      return savedPosition;
    }
    return { left: 0, top: 0, behaviour: "smooth" };
  };
});

The problem is I think it's scrolling earlier than the page loads, so there's a weird jumping effect on the page.

Here is a video of the issue: https://user-images.githubusercontent.com/22452368/154849559-3974fc01-e265-486b-865b-55ee03053fa8.mp4

Can you help me see what's wrong here? Or is there a bug in Nuxt 3?

P粉885562567P粉885562567268 days ago393

reply all(1)I'll reply

  • P粉696146205

    P粉6961462052024-03-26 13:12:12

    You can try the solution mentioned in nuxt question< /p>

    // app/router.options.js
    export default {
      scrollBehavior() {
        return { top: 0 }
      },
    }

    reply
    0
  • Cancelreply