Learn Programming, Tech & Coding · Free Online Tools

IT Question Answer
Back to Next.js
Next.js App Router vs Pages Router

Next.js App Router vs Pages Router

Next.js727 viewsBy Admin
nextjsrouterpages

Two Routing Systems

Next.js has two routers: the older Pages Router (pages/) and the newer App Router (app/, introduced in Next 13). New projects should use the App Router.

Key Differences

FeaturePages RouterApp Router
Folderpages/app/
ComponentsClient by defaultServer by default
Data fetchinggetServerSidePropsasync components + fetch
LayoutsManualNested layout.tsx
Loading UIManualloading.tsx

Data Fetching Comparison

// Pages Router
export async function getServerSideProps() {
  const data = await fetch("...").then(r => r.json());
  return { props: { data } };
}

// App Router — just await in the component
export default async function Page() {
  const data = await fetch("...").then(r => r.json());
  return <div>{data.title}</div>;
}

Server vs Client Components

// Server Component (default) — runs on server, no JS shipped
export default async function Page() { ... }

// Client Component — needs interactivity/hooks
"use client";
export default function Counter() { const [n] = useState(0); ... }

FAQs

Can I use both routers together?

Yes, during migration. But pick the App Router for new features.

Is the Pages Router deprecated?

Not deprecated, but the App Router is the future and gets new features first. More in our Next.js section.