Migrate Pages Router component to App Router

VerifiedSafe

Migrate a React component from Next.js Pages Router to App Router. Handles conversion of data fetching methods (getServerSideProps, getStaticProps), routing patterns, and hooks like useRouter and Head. Use when modernizing legacy Next.js pages to the App Router pattern.

Sby Skills Guide Bot
DevelopmentAdvanced
1006/2/2026
Claude CodeCursorWindsurf
#nextjs#pages-router#app-router#migration#component-migration

Recommended for

Our review

This skill migrates Next.js components or pages from the Pages Router to the App Router following a defined architecture.

Strengths

  • Automates conversion of page files and API routes
  • Transforms server-side data methods (getServerSideProps, getStaticProps) into async server components
  • Handles separation of server and client components
  • Automatically creates loading.tsx and error.tsx files

Limitations

  • Requires files to already be compliant with Next.js Pages Router
  • Does not handle complex nested dynamic routing cases
  • Requires manual execution of validation commands
When to use it

When a Next.js project using the Pages Router needs to be migrated to the App Router.

When not to use it

For partial migrations or when the target architecture is not yet clearly defined.

Security analysis

Safe
Quality score85/100

The skill only performs code analysis, file editing, and runs standard build/lint/test commands (tsc, next build, vitest) for validation. No destructive, exfiltrating, or obfuscated actions are involved.

No concerns found

Examples

Migrate a page to App Router
Migrate the file pages/products/[id].tsx to the App Router following the architecture documentation.
Convert legacy data fetching
Convert getServerSideProps in components/UserProfile.tsx to async server component pattern.
Full component migration
I need to migrate my component MyComponent from Pages Router to App Router. The file is at src/components/MyComponent.tsx.

name: migration-migrate-component description: "Use when a component needs migration to the target architecture or framework version." user-invocable: true argument-hint: "[component-file]" allowed-tools: Read, Write, Edit, Bash, Glob, Grep

Migrate a Pages Router component/page to App Router following docs/ARCHITECTURE.md sections 5 and 6.

Component: $ARGUMENTS

Steps

  1. Read docs/ARCHITECTURE.md sections 5 and 6.

  2. Analyze the component/page:

    • Count lines (JSX, logic)
    • List: props, state, effects, data fetching methods
    • Check for getServerSideProps, getStaticProps, getStaticPaths
    • Check for useRouter from next/router
    • Check for Head component usage
    • Map who imports this component
  3. Convert routing:

    • pages/xxx.tsx -> app/xxx/page.tsx
    • pages/xxx/[id].tsx -> app/xxx/[id]/page.tsx
    • pages/api/xxx.ts -> app/api/xxx/route.ts (or Server Action)
  4. Convert data fetching:

    • getServerSideProps -> async Server Component (service + adapter)
    • getStaticProps -> async Server Component + revalidate
    • getStaticPaths -> generateStaticParams()
    • Client-side useEffect + fetch -> React Query hook
  5. Determine Server vs Client:

    • Data fetching only? -> Server Component
    • Has hooks, events, browser APIs? -> Client Component
    • Mixed? -> Split into Server page + Client component
  6. Convert imports:

    • useRouter from next/router -> useRouter + usePathname + useSearchParams from next/navigation
    • Head -> metadata export or generateMetadata()
  7. Create siblings:

    • loading.tsx -- skeleton matching page structure
    • error.tsx -- error boundary ('use client' required)
  8. Type all props.

  9. Decompose if > 200 lines.

  10. Validate:

npx tsc --noEmit
npx next build
npx vitest run --passWithNoTests
Related skills