Mohamed GhoniemWeb Developer
MohamedGhoniem
  • Work
  • Services
  • Experience
  • Blog
Available
CV
Open to opportunities
WorkServicesExperienceBlogDownload CV
All blogs

© 2026 Mohamed Ghoniem. All rights reserved.

TwitterGitHubLinkedIn
Smooth page transitions with Framer Motion and Next.js App Router
DesignFrontend
All blogs

Smooth page transitions with Framer Motion and Next.js App Router

MG
Mohamed Ghoniem
·July 16, 2026·7 min read

Prefer to watch?

This article has a full video walkthrough on YouTube

Watch the same walkthrough on YouTube.

The challenge of App Router transitions

In the Next.js App Router, routing is handled on the server side, which means pages are replaced instantly without giving standard client-side libraries a chance to animate the entrance and exit of elements easily.

Framer Motion implementation

To implement smooth transitions, we wrap pages in a client-side layout that intercepts route events or leverages unique React keys to trigger exit and entrance animations.

jsx
// Template wrapper for route animations
'use client'
import { motion } from 'framer-motion'

export default function Template({ children }) {
  return (
    <motion.div
      initial={{ y: 20, opacity: 0 }}
      animate={{ y: 0, opacity: 1 }}
      exit={{ y: -20, opacity: 0 }}
      transition={{ ease: 'easeInOut', duration: 0.4 }}
    >
      {children}
    </motion.div>
  )
}

Best practices for web animation

Keep animations subtle. Use spring physics for interactive elements (like cards and buttons) and duration-based curves (like ease-out) for entry/exit page transitions to prevent UI lag.

On this page7 min left
The challenge of App Router transitionsFramer Motion implementationBest practices for web animation

Share

On this page7 min left
The challenge of App Router transitionsFramer Motion implementationBest practices for web animation

Written by

Mohamed Ghoniem

I build fast, responsive web experiences, from pixel-perfect UI to the backend behind it.

Get in touchAll posts
Older postAdvanced TypeScript patterns every React dev should knowNewer postJWT refresh token rotation — the right way
Keep reading
Building a design system from scratch with Figma tokens & Tailwind
DesignFrontendJuly 16, 2026

Building a design system from scratch with Figma tokens & Tailwind

A practical walkthrough of how I set up a token-driven design system that stays in sync between Figma and code — no plugin lock-in, no manual updates.

MG
Mohamed G.
8 min read
The hidden cost of unoptimized images in Next.js
DesignFrontendJuly 16, 2026

The hidden cost of unoptimized images in Next.js

A practical walkthrough of how I set up a token-driven design system that stays in sync between Figma and code — no plugin lock-in, no manual updates.

MG
Mohamed G.
5 min read
JWT refresh token rotation — the right way
DesignFrontendJuly 16, 2026

JWT refresh token rotation — the right way

A practical walkthrough of how I set up a token-driven design system that stays in sync between Figma and code — no plugin lock-in, no manual updates.

MG
Mohamed G.
6 min read