Migrate Next.js Pages Router code to modern App Router with Server Components
Migrates Next.js Pages Router to App Router with Server Components. Analyzes your project, converts pages to Server Components, transforms API routes to Server Actions, and updates data fetching patterns. Use it to modernize your Next.js app incrementally with interactive step-by-step guidance.
/plugin marketplace add Tylerbryy/codewarden/plugin install codewarden@codewarden-marketplaceGuide migration from Next.js Pages Router to the modern App Router architecture with Server Components, Server Actions, and React 19 patterns.
When this command is invoked:
Analyze current setup:
pages/ directory)getServerSideProps/getStaticProps usageCreate migration plan:
Execute migration (with user confirmation at each step):
Step 1: Setup App Directory
app/ directoryStep 2: Migrate Pages
getServerSideProps logic into componentStep 3: Convert Data Fetching
useEffect data fetchinguse() for streaming where neededStep 4: Migrate API Routes
Step 5: Update Components
Validation:
Cleanup:
Before (Pages Router):
// pages/dashboard.tsx
export async function getServerSideProps() {
const data = await fetchDashboardData()
return { props: { data } }
}
export default function Dashboard({ data }) {
return <DashboardUI data={data} />
}
After (App Router):
// app/dashboard/page.tsx
export default async function Dashboard() {
const data = await fetchDashboardData()
return <DashboardUI data={data} />
}
Before:
// pages/api/update-profile.ts
export default async function handler(req, res) {
const { name } = req.body
await updateUser(name)
res.json({ success: true })
}
After:
// actions/profile.ts
"use server"
export async function updateProfile(formData: FormData) {
const session = await auth()
if (!session) return { error: 'Unauthorized' }
const name = formData.get('name')
await updateUser(session.user.id, name)
revalidatePath('/profile')
return { success: true }
}
Before:
"use client"
function Users() {
const [users, setUsers] = useState([])
useEffect(() => {
fetch('/api/users').then(r => r.json()).then(setUsers)
}, [])
return <UserList users={users} />
}
After:
// Server Component
async function Users() {
const users = await db.query.users.findMany()
return <UserList users={users} />
}
/migrate-to-app-router
# Full interactive migration
/migrate-to-app-router --analyze-only
# Just show migration plan without executing
/migrate-to-app-router pages/dashboard.tsx
# Migrate specific page
/migrate-to-app-router --api-routes
# Convert API routes to Server Actions only
Before migration:
During migration:
After migration: