Next.js

Getting Started with the Next.js App Router

A reference guide to the Next.js App Router: file conventions, layouts, and data fetching.

Ava ChenMarch 1, 2026 (updated July 1, 2026)2 min read
Share:

This is a reference-style guide to the core conventions of the Next.js App Router.

File conventions

FilePurpose
layout.tsxShared UI that wraps a segment and its children
page.tsxThe unique UI for a route, making it publicly accessible
loading.tsxLoading UI shown while a segment loads
not-found.tsxUI rendered when notFound() is called
error.tsxError boundary for a segment
route.tsAn API endpoint (Route Handler) for a segment

Nested layouts

Layouts nest automatically based on folder structure. A layout.tsx in app/blog/ wraps every route under /blog, in addition to the root layout.

app/ layout.tsx → wraps everything blog/ layout.tsx → wraps everything under /blog page.tsx → /blog [slug]/ page.tsx → /blog/[slug]

Static params for dynamic routes

For a fully static export, every dynamic segment needs generateStaticParams so Next.js knows every path to pre-render at build time.

tsx
export async function generateStaticParams() {
  const posts = getAllPosts();
  return posts.map((post) => ({ slug: post.slug }));
}

Metadata

Each route can export a generateMetadata function to produce per-page <title>, description, and Open Graph tags at build time.

tsx
export async function generateMetadata({ params }) {
  const { slug } = await params;
  const post = getPostBySlug(slug);
  return { title: post.title, description: post.description };
}

Server vs. Client Components

By default, every component in app/ is a Server Component. Add "use client" at the top of a file only when you need interactivity, browser APIs, or React hooks like useState.

Advertisement
Ava Chen
Ava Chen

Senior Software Engineer

Ava writes about frontend architecture, React, and TypeScript. Previously built developer tools at scale-up startups.

Related Articles