vue.jsnuxt.jsgsap

Nuxt page transition timing


How does nuxt calculate the time before it redirects/switches to the new page between page transitions? I know it's done automatically when defining transitions through CSS however I'm using GSAP for my animation. Will nuxt figure the time by themself or am I required to set it?


Solution

  • Here you could find the actual flow of client-side navigation

    1. Navigation triggered.
    2. Call beforeRouteLeave guards in deactivated components.
    3. Call global beforeEach guards.
    4. Call beforeRouteUpdate guards in reused components.
    5. Call beforeEnter in route configs.
    6. Resolve async route components.
    7. Call beforeRouteEnter in activated components.
    8. Call global beforeResolve guards.
    9. Navigation is confirmed.
    10. Call global afterEach hooks.
    11. DOM updates triggered.
    12. Call callbacks passed to next in beforeRouteEnter guards with instantiated instances.

    Here are the various steps regarding the CSS transitions in Vue


    And here are Nuxt global page transitions

    nuxt.config.js

    export default {
      buildModules: ['nuxt-gsap-module'],
    
      // Add global page transition
      pageTransition: {
        name: 'page',
        mode: 'out-in',
        css: false,
    
        beforeEnter(el) {
          this.$gsap.set(el, {
            opacity: 0
          })
        },
    
        enter(el, done) {
          this.$gsap.to(el, {
            opacity: 1,
            duration: 0.5,
            ease: 'power2.inOut',
            onComplete: done
          })
        },
    
        leave(el, done) {
          this.$gsap.to(el, {
            opacity: 0,
            duration: 0.5,
            ease: 'power2.inOut',
            onComplete: done
          })
        }
      }
    }
    

    There is no special magic here: just Nuxt using the hooks available for the transitions.