Skip to content
RoutingChapter 4 / 34Beginner4 min read

Routing & Pages

Next.js App Router pages explained: how folders become routes, the role of page.tsx, nested routes, and how to await searchParams, for beginners.

On this page

1. What are routing and pages?

This is called file-based routing. You do not write a route list or a router config. Create a folder, put a page.tsx in it, and the route exists.

2. Why does it matter?

In client-side routers, routes are defined in code, and as the app grows the list gets long and confusing.

Config-based routingNext.js file-based routing
Routes in one long listThe folder structure is the route map
A new page = edit the configA new page = a new folder
Remember how URLs map to filesYou can find the file from the URL
You do code splitting yourselfEvery route is split automatically

3. Where is it used?

URLFile
/app/page.tsx
/aboutapp/about/page.tsx
/blogapp/blog/page.tsx
/dashboard/settingsapp/dashboard/settings/page.tsx
/blog/helloapp/blog/[slug]/page.tsx (dynamic route)

4. How does it work?

Creating a folder makes a route segment, but it becomes public only when it contains a page.tsx (or route.ts). A folder without page.tsx is just for organization.

From URL to page
The browser opens /dashboard/settings
app folder
dashboard folder
settings folder
page.tsx renders

A route segment can have other special files too:

FilePurpose
page.tsxThe route's unique UI
layout.tsxShared UI that stays in place during navigation
loading.tsxThe loading state
error.tsxAn error boundary
not-found.tsxThe 404 UI
route.tsAn API endpoint (Route Handler)

5. Code example

A simple page

tsx
export default function AboutPage() {
  return (
    <main>
      <h1>About us</h1>
      <p>This page comes from app/about/page.tsx.</p>
    </main>
  );
}

A page with searchParams

The query values of the URL /products?sort=price&page=2 reach the page in the searchParams prop. In Next.js 16 this is a Promise.

tsx
export default async function ProductsPage({
  searchParams,
}: PageProps<"/products">) {
  const { sort = "newest", page = "1" } = await searchParams;

  return (
    <main>
      <h1>Products</h1>
      <p>
        Sort: {sort}, Page: {page}
      </p>
    </main>
  );
}

How does the code work?

PartMeaning
export defaultThe page component must be the default export
app/about/page.tsxThe /about route
PageProps<"/products">A global type helper, the props type comes from the route
await searchParamsThe query string values, async in Next.js 16
sort = "newest"A default value when the URL has no query

Interview tip

"What is the relationship between folders and routes?" The answer: a folder creates a segment, but the route becomes public only when the segment has a page or route file.

6. Common mistakes

Mistake: Making the page component a named export

Why? Next.js treats only the default export as the page, and a named export gives a 404 for the route.

Better: Write export default function PageName().

Mistake: Creating a folder but not adding page.tsx

Why? A segment without a page file does not become a public route.

Better: Always put a page.tsx in the folder of every public route.

Mistake: Reading searchParams as a plain object

Why? In Next.js 16 it is a Promise, and accessing a property directly gives undefined.

Better: Use await searchParams in a Server Component, and the useSearchParams hook in a Client Component.

7. What to learn before and after

Final quick revision

PointDetail
Routing typeFile-based, the app/ folder
When a route is publicThe folder has a page.tsx
ExportA default exported component
Query stringsearchParams, remember to await it
Type helperPageProps<"/route">