Skip to main content

Next.js App Router Migration Guide

Migrate a Next.js Pages Router app to the App Router with route mapping, server-component data fetching, streaming, and parallel routes.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
You are a Next.js migration specialist. Guide me through migrating a my-nextjs-app application from Pages Router to the App Router architecture.

Step 1: Inventory all routes in the src/pages directory. For each route, document the current data-fetching method (getServerSideProps, getStaticProps, getStaticPaths, or client-side) and any middleware applied. Output a migration priority matrix sorted by complexity (low/medium/high).

Step 2: Create the new App Router directory structure under src/app. Map each page to its corresponding route segment with proper layout nesting. Identify shared layouts across 3 route groups and design the layout hierarchy to maximize code reuse.

Step 3: Migrate data fetching by converting getServerSideProps to async server components with direct fetch calls, getStaticProps to fetch with revalidation options, and getStaticPaths to generateStaticParams. Show the exact code transformation for each pattern used in this project.

Step 4: Implement loading.tsx and error.tsx files for each route segment to replace custom loading states. Design Suspense boundaries around ProductReviews and similar data-heavy components to enable streaming SSR.

Step 5: Convert any API routes from pages/api to Route Handlers in the app directory. Ensure each handler exports the correct HTTP method functions (GET, POST, PUT, DELETE) and returns NextResponse objects.

Step 6: Set up parallel routes for any modal patterns or split-view layouts in the application. Implement intercepting routes for /products/[id]/quick-view to enable soft navigation while preserving direct URL access.

What this prompt does

This prompt casts the AI as a Next.js migration specialist guiding a [project_name] app from the Pages Router to the App Router. It inventories every route in [pages_directory], documenting each one's data-fetching method and middleware, then outputs a migration priority matrix sorted by complexity. Next it builds the App Router structure under [app_directory], mapping pages to route segments and designing layout nesting across [route_group_count] route groups. The explicit route inventory is what keeps the migration from missing edge routes.

The structure works because the App Router changes data fetching fundamentally. It converts getServerSideProps to async server components, getStaticProps to fetch with revalidation, and getStaticPaths to generateStaticParams, with exact before/after code. It then adds loading.tsx and error.tsx per segment with Suspense around [slow_component], converts pages/api routes to Route Handlers, and sets up parallel and intercepting routes for [modal_route] to preserve soft navigation and direct URL access. The [route_group_count] route groups let the AI design a layout hierarchy that maximizes shared code instead of duplicating shells across pages, and the loading.tsx plus error.tsx convention replaces the custom loading and error states the Pages Router required you to hand-roll. Converting pages/api handlers to Route Handlers shifts each endpoint to exporting explicit HTTP-method functions returning NextResponse, which is a different shape from the old default-export handler and worth getting right early.

When to use it

  • You are migrating a Next.js app from Pages Router to App Router
  • You want a complexity-ranked route inventory to plan the order of work
  • You need exact conversions for getServerSideProps, getStaticProps, and getStaticPaths
  • You want streaming via Suspense around data-heavy components
  • You are converting pages/api routes to Route Handlers
  • You need parallel and intercepting routes for modal patterns

Example output

The AI returns a route inventory and migration priority matrix, an App Router directory structure under [app_directory] with nested layouts across [route_group_count] route groups, exact before/after transformations for each data-fetching pattern, loading.tsx and error.tsx files per segment with Suspense around [slow_component], Route Handlers replacing pages/api with correct HTTP method exports and NextResponse, and parallel plus intercepting routes for [modal_route] enabling soft navigation with direct URL access.

Pro tips

  • Start with the low-complexity routes from the priority matrix to build momentum and confidence
  • The getServerSideProps-to-async-server-component conversion is what quietly breaks things — lean on the before/after mapping
  • Use generateStaticParams to replace getStaticPaths; the signature and return shape differ enough to bite you
  • Place loading.tsx and error.tsx per segment so streaming and error handling come almost for free
  • Plan parallel and intercepting routes for [modal_route] early; modals are usually the last 10% nobody scopes
  • Confirm each Route Handler exports the right method functions (GET, POST, etc.) and returns NextResponse

Frequently Asked Questions

How are the old data-fetching methods converted?
getServerSideProps becomes an async server component with direct fetch calls, getStaticProps becomes fetch with revalidation options, and getStaticPaths becomes generateStaticParams. The prompt shows the exact before/after for each pattern used in your project, which is where most breakage hides.
What happens to my pages/api routes?
They are converted to Route Handlers in the app directory, each exporting the correct HTTP method functions (GET, POST, PUT, DELETE) and returning NextResponse objects. This replaces the old API route handler signature with the App Router convention.
Does it handle modal patterns during the migration?
Yes. It sets up parallel routes for split-view and modal layouts and intercepting routes for `[modal_route]`, so modals open via soft navigation but still work when the URL is visited directly. These are typically the last details a migration plan overlooks.
How does it decide what to migrate first?
The route inventory produces a migration priority matrix sorted by complexity (low, medium, high), documenting each route's current data-fetching method and middleware. Starting with low-complexity routes lets you validate the approach before tackling the hard ones.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in React & Next.js Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support