Next.js 16 cheatsheet
Next.js 16: Routing and files
7 common Next.js 16 tasks.
Create a page
A page.tsx file inside app/ is a route. This one serves /about from app/about/page.tsx.
export default function Page() {
return <h1>About</h1>;
}
Create a layout
A layout wraps its pages and persists across navigation.
export default function Layout({ children }: { children: React.ReactNode }) {
return <section>{children}</section>;
}
Read a dynamic route parameter
In app/blog/[slug]/page.tsx, params is a promise, so await it.
export default async function Page({ params }: { params: Promise<{ slug: string }> }) {
const { slug } = await params;
return <h1>{slug}</h1>;
}
Link between pages
Navigate on the client without a full page reload.
import Link from "next/link";
<Link href="/about">About</Link>
Create an API route
A route.ts file exports a function per HTTP method.
export async function GET() {
return Response.json({ ok: true });
}
Show a loading state
A loading.tsx next to a page is shown while the page streams in.
export default function Loading() {
return <p>Loading...</p>;
}
Return a 404
Call notFound() in a server component to render the closest not-found page.
import { notFound } from "next/navigation";
if (!post) notFound();