Giter Site home page Giter Site logo

jonas-cardoso / enter-exit-page-transitions-with-next.js Goto Github PK

View Code? Open in Web Editor NEW
3.0 0.0 3.0 52 KB

Intercept Transition between routes in Next.js 13/14 and call Exit animations with a <Navigate> component that can be extended.

Home Page: https://main--enter-exit-animations-nextjs.netlify.app/

TypeScript 96.03% JavaScript 3.09% CSS 0.89%

enter-exit-page-transitions-with-next.js's Introduction

Enter/Exit Page Transitions with Next.js 14

Getting Started

With the release of Next.js 13, the App folder was introduced, which resulted in the removal of support for next/router. As a workaround to implement page transitions, you need to navigate programmatically by intercepting the route and invoking the route transition via the Context API.

Implementation Details

This project structure serves as a base for larger projects. Here are a few important notes to consider during implementation:

Forward/Backward Browser Navigation

To enable smooth transitions with forward/backward browser navigation, consider utilizing the useLayoutEffect hook without a dependency array. This approach makes the transition logic execute each time the navigation occurs.

UseLayout will update the loading states after the route has loaded and changes have been calculated, will then sync the transition before it gets painted. Thus you can manipulate what the user actually sees right before the route initial render.

Integration with Framer Motion

For integration with Framer Motion, replace the init/_enter/_exit functions with the respective initial/animate/exit behavior.

Add a FINISHED = "FINISHED" property to the LOADING_STATES enum.

export enum LOADING_STATES {
  INIT = "INITIALIZED",
  LOADING = "PENDING",
  LOADED = "COMPLETE",
  FINISHED = "FINISHED",
}

Add logic to the _enter function so it adds the Framer motion finished state if the animation has been loaded.

if (loading === LOADING_STATES.LOADED) {
  //once animation is complete
  setLoading(LOADING_STATES.FINISHED);
}

Conditionally render the loader based on the FINISHED state.

{loading != LOADING_STATES.FINISHED && (<>Component</>)}

enter-exit-page-transitions-with-next.js's People

Contributors

jonas-cardoso avatar

Stargazers

 avatar Felix avatar Rachael Miki Buxton avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.