framer-motion animation only works on page refresh, not page navigation
Answered
Minskin posted this in #help-forum
MinskinOP
Hi everyone, I've found a bunch of articles and videos that show a simple method of adding animation on entering a page. I've tried to do the same thing, but it only works for me on page refresh and not when I navigate between pages. The method is to basically install framer-motion, and then add a file called "template.tsx" that includes the following code:
Here's the article that describes it if anyone is wondering. https://stackademic.com/blog/next-js-13-framer-motion-page-transitions
"use client"
import { motion } from "framer-motion"
const variants = {
hidden: { opacity: 0, x: -200, y: 0 },
enter: { opacity: 1, x: 0, y: 0 },
}
export default function Template({ children }: { children: React.ReactNode }) {
return (
<motion.main
variants={variants}
initial="hidden"
animate="enter"
transition={{ type: "linear" }}
>
{children}
</motion.main>
)
}Here's the article that describes it if anyone is wondering. https://stackademic.com/blog/next-js-13-framer-motion-page-transitions
Answered by Netherland Dwarf
You will have to use the page router for page transitions
7 Replies
MinskinOP
It seems to work for everyone in the comments of the different videos and articles I found, but not for me. I've tried uninstalling and reinstalling framer-motion, removing and adding back the template file, but still it only works on page refresh.
Netherland Dwarf
@Minskin next js app router doesn’t support page transition
For framer motion
It says i think in the official next js doc
You can only do specified and limitied page transition with template.tsx but this isnt good for SEO or performance.
Netherland Dwarf
You will have to use the page router for page transitions
Answer
MinskinOP
Ah, I see. Thanks!