$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
Migration & Upgradesadvanced

Next.js Migration

Share

Migrate from Pages Router to App Router

Works with OpenClaude

You are a Next.js migration specialist. The user wants to migrate an existing Pages Router project to the App Router architecture.

What to check first

  • Run cat package.json and verify Next.js version is 13.4 or higher
  • Check ls -la for existing pages/ directory structure and count of route files
  • Run next --version to confirm the installed Next.js version supports App Router
  • Review next.config.js for any custom webpack, redirects, or rewrites that need porting

Steps

  1. Create the app/ directory at root level alongside pages/ (both can coexist during migration)
  2. Convert pages/_app.tsx to app/layout.tsx — move global styles, providers, and context wrappers into the root layout
  3. Convert pages/_document.tsx to app/layout.tsx — merge <html>, <head>, and <body> structure using the RootLayout component
  4. Migrate route files: convert pages/blog/[id].tsx to app/blog/[id]/page.tsx (nested folder + page.tsx file)
  5. Convert API routes: move pages/api/users.ts to app/api/users/route.ts and refactor handlers to use NextRequest/NextResponse
  6. Update dynamic routes using getStaticProps/getServerSideProps — replace with Server Components or generateStaticParams() for static generation
  7. Port middleware: move middleware.ts from project root to app/middleware.ts and update matcher patterns if needed
  8. Remove pages directory entirely and verify all routes resolve using npm run dev and test each migrated endpoint

Code

// Step 1: Convert pages/_app.tsx to app/layout.tsx
import type { ReactNode } from 'react'
import './globals.css'

export const metadata = {
  title: 'My App',
  description: 'Generated by Next.js',
}

export default function RootLayout({
  children,
}: {
  children: ReactNode
}) {
  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  )
}

// Step 2: Convert pages/blog/[id].tsx to app/blog/[id]/page.tsx
import { notFound } from 'next/navigation'

interface PageProps {
  params: Promise<{ id: string }>
}

export async function generateStaticParams() {
  const posts = await fetch('https://api.example.com/posts')
    .then((res) => res.json())
  return posts.map((post: { id: string }) => ({
    id: post.id,
  }))
}

export default async function BlogPage({ params }: PageProps) {
  const { id } = await params
  const post = await fetch(`https://api.example.com/

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

Difficultyadvanced
Version1.0.0
AuthorClaude Skills Hub
migrationnextjsapp-router

Install command:

curl -o ~/.claude/skills/nextjs-migration.md https://claude-skills-hub.vercel.app/skills/migration/nextjs-migration.md

Related Migration & Upgrades Skills

Other Claude Code skills in the same category — free to download.

Want a Migration & Upgrades skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.