Nextjs Migration Auto
Battle-tested command for comprehensive, next, migration, assistant. Includes structured workflows, validation checks, and reusable patterns for nextjs vercel.
Next.js Migration Auto
Automate Next.js migration from Pages Router to App Router with file structure analysis, automatic route conversion, layout generation, and migration complexity scoring.
When to Use This Command
Run this command when you need to migrate a Next.js application from the Pages Router to the App Router architecture.
- You have an existing Pages Router application and want to adopt the App Router
- You need to assess migration complexity before committing to the work
- You want automated conversion of
_app.tsx,_document.tsx, and page files to App Router equivalents - You need to migrate API routes from
pages/api/toapp/api/with the new route handler format
Use it also when:
- You want a hybrid migration strategy that runs both routers simultaneously
- You need to update data fetching from
getServerSideProps/getStaticPropsto Server Components
Quick Start
# .claude/commands/nextjs-migration-auto.md name: nextjs-migration-auto description: Migrate Next.js from Pages Router to App Router arguments: mode: analyze | migrate | hybrid
# Analyze migration complexity first claude nextjs-migration-auto "analyze"
Expected output:
Migration Analysis:
Current: Pages Router (Next.js 13.4.1)
Pages: 24 files in pages/
API Routes: 8 files in pages/api/
Custom _app: Yes (providers, global state)
Custom _document: Yes (fonts, meta tags)
Complexity Score: 6/10
Estimated Effort:
Automated: 18 files (75%)
Manual Review: 6 files (25%)
Risk Areas: _app.tsx providers, getServerSideProps
Core Concepts
| Concept | Description |
|---|---|
| Pages Router | Legacy routing via pages/ directory with getServerSideProps |
| App Router | Modern routing via app/ directory with Server Components |
| Layout | Shared UI wrapper replacing _app.tsx in the App Router |
| Route Handler | App Router API routes using export async function GET() syntax |
| Complexity Score | 1-10 rating based on file count, custom features, and data fetching |
Migration Path:
pages/_app.tsx āāāāāāāāā> app/layout.tsx
pages/_document.tsx āāāā> app/layout.tsx (head elements)
pages/index.tsx āāāāāāāā> app/page.tsx
pages/about.tsx āāāāāāāā> app/about/page.tsx
pages/api/users.ts āāāā> app/api/users/route.ts
getServerSideProps āāāā> Server Component (direct fetch)
getStaticProps āāāāāāāā> generateStaticParams + fetch
Configuration
| Parameter | Default | Description |
|---|---|---|
mode | analyze | Operation mode: analyze, migrate, hybrid |
target-version | latest | Target Next.js version for migration |
include-api | true | Migrate API routes alongside pages |
preserve-pages | false | Keep original pages/ files during migration |
dry-run | false | Generate migration plan without making changes |
Best Practices
-
Always run analyze first -- Understand the migration complexity and effort estimate before starting. Address risk areas identified in the analysis.
-
Migrate incrementally with hybrid mode -- Use
hybridmode to run both routers simultaneously, migrating one route at a time rather than all at once. -
Start with leaf pages, not layouts -- Migrate simple pages without shared state first, then tackle
_app.tsxand layout-heavy pages once you are comfortable. -
Update data fetching patterns -- Replace
getServerSidePropswith directfetch()in Server Components. ReplacegetStaticPropswithgenerateStaticParams. -
Test each migrated route individually -- After migrating a route, verify it works in both development and production builds before moving to the next one.
Common Issues
-
Client-side state in _app.tsx -- Context providers and global state in
_app.tsxmust be wrapped in a Client Component and placed in the rootlayout.tsx. -
Dynamic routes syntax change -- Pages Router
[id].tsxbecomes[id]/page.tsxin the App Router. Ensure all dynamic segments are migrated to directory-based routing. -
getServerSideProps not available in App Router -- App Router does not support
getServerSideProps. Data fetching happens directly in Server Components usingfetch()with caching options.
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Git Commit Message Generator
Generates well-structured conventional commit messages by analyzing staged changes. Follows Conventional Commits spec with scope detection.
React Component Scaffolder
Scaffolds a complete React component with TypeScript types, Tailwind styles, Storybook stories, and unit tests. Follows project conventions automatically.
CI/CD Pipeline Generator
Generates GitHub Actions workflows for CI/CD including linting, testing, building, and deploying. Detects project stack automatically.