Convert Next.js Pages Router to App Router
npm install next-page-to-app-convertergetServerSideProps and getStaticProps to async Server Components, including generateStaticParams.
next/router to next/navigation (useRouter, usePathname, useSearchParams).
res methods to NextResponse.
tags to the Metadata API.
_app.tsx.
next/font configurations.
bash
npx next-page-to-app-converter
`
$3
`bash
npm install -g next-page-to-app-converter
next-pages-to-app
`
⚙️ Options
| Flag | Description |
| :--- | :--- |
| -d, --dry-run | Preview the migration without writing any files. |
| -v, --validate | (Experimental) Runs runtime validation using Next.js DevTools (Requires Next.js 16+). |
| -h, --help | Show all available commands and options. |
🛠️ How It Works
1. Scans your pages directory for routes, API endpoints, and special files (_app, _document, _error).
2. Analyzes every component (and its imports) to detect:
* React Hooks (useState, useEffect, etc.)
* Event Handlers (onClick, onChange)
* Browser-only APIs (window, localstorage)
3. Transforms the code:
* Adds "use client" directives where needed.
* Rewrites data fetching to async Server Components.
* Updates navigation and routing logic.
4. Generates the new folder structure in the app directory, preserving your logic.
✅ Requirements
* Node.js: 18.0.0 or later
* Target Project: Next.js 13 or later (Next.js 16+ required for --validate)
❓ Troubleshooting
* Validation Issues: The --validate flag relies on starting your dev server. Ensure npm run dev` works on your project manually before running the tool.