Giter Site home page Giter Site logo

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

Enter/Exit Page Transitions with Next.js 14

Getting Started

To set up the project, run the following commands in your terminal:

npm i
npm run dev

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, one can utilize a custom Component. This component facilitates navigation 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 useEffect hook without a dependency array. This approach makes the transition logic execute each time the navigation occurs.

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 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

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.