The exit animation does not work with Next.js 16.2.6 and Framer Motion 12.4.0 #3736
|
Greetings, I am trying to implement the page transition for each page with Framer Motion v12.40.0. My goal is when users click on the link on the navigation bar, the current page will perform the exit animation, then go to the next page. But I encounter an issue that the exit animation does not work, only the enter animation works. My approach is to write an animate wrapper then apply to each page. This is the complete code for the navigation bar. This is the complete code for This is the complete code for the animate wrapper (/component/AnimateWrapper.tsx) in the client component. This is the complete code for home page, I apply the animate wrapper to each code including the home page. I have read the official doc, the motion.div tag in the needs a key prop to enable the exit animation, but I don't know the proper value for the key prop, or if there are something missing. Thank you in advance for any solutions and answers. |
Replies: 1 comment 1 reply
|
The root cause is the architecture of Next.js App router have completely changed compare to the conventional page router. There are 2 ways which might be helpful. The first way is to restart your Next.js project with the conventional page router. Next.js still allows users to choose the page router even though the latest version. If you insist on the app router, then there is a library called next-transition-router. https://github.com/ismamz/next-transition-router And here is the test website which on my GitHub repository. https://github.com/robin-artemstein/nextjs-company-website-framer-motion Best of luck. |
The root cause is the architecture of Next.js App router have completely changed compare to the conventional page router.
There are 2 ways which might be helpful.
The first way is to restart your Next.js project with the conventional page router.
Next.js still allows users to choose the page router even though the latest version.
If you insist on the app router, then there is a library called next-transition-router.
https://github.com/ismamz/next-transition-router
And here is the test website which on my GitHub repository.
https://github.com/robin-artemstein/nextjs-company-website-framer-motion
Best of luck.