Next.js App Router Cheat Sheet: Files, Caching, Route Handlers
Checked against Next.js Next.js 16.4.6 (latest on npm); notes for 15.5, which this site runs (15.5.29) on 28 November 2026. Each section links to the official docs it was checked against.
This sheet is for developers building with the Next.js App Router who want the file names and caching APIs on one page. It follows the nextjs.org docs for Next.js 16 (16.4.6 was the latest release on 28 Nov 2026) and flags where Next.js 15 differs, since plenty of apps, including this one on 15.5.29, have not moved yet. Rows are from the docs and were not run in a fresh app.
When to use what
Leave components as Server Components unless they need state, event handlers, effects or browser APIs. Put 'use client' on the smallest interactive piece, such as a search box, not on a whole layout, because everything that file imports joins the client bundle. You can still pass Server Components into a client wrapper as children.
Caching is the part that changed most. In Next.js 15 without Cache Components, fetch is not cached by default; you opt in with cache: 'force-cache' or next: { revalidate } and tune routes with export const dynamic and revalidate. In Next.js 16 you can turn on cacheComponents, and then nothing is cached unless you mark it with 'use cache' plus a cacheLife profile. Uncached reads must sit inside <Suspense> so the rest of the page can still be prerendered. New apps from create-next-app have it on already. I would turn it on for new projects and migrate older ones route by route, because the mental model is simpler once you are there.
After a mutation, use updateTag() in a Server Action when the user must see their own change right away, and revalidateTag(tag, 'max') when stale-while-revalidate is fine. Use a route.ts handler for webhooks and endpoints other clients call, and Server Actions for your own forms. Our caching strategies post, Server Actions guide and Next.js 15 migration guide go further.
A folder becomes a public route only when it has a page or route file. In Next.js 16 every parallel route slot needs a default.js.
app/layout.tsxRoot layout that wraps every route; must render <html> and <body>
page.tsxUI for a route segment and the file that makes the URL public
loading.tsxSuspense fallback shown while the segment loads
error.tsx / global-error.tsxError boundary for a segment, and one for the root layout
not-found.tsxUI rendered when notFound() is called or no route matches
route.tsHTTP endpoint; cannot sit in the same segment as a page
template.tsxLike a layout but re-mounted on every navigation
default.tsxFallback for a parallel route slot that has no match
proxy.tsRequest interception at the project root; replaces middleware.ts in Next.js 16
app/blog/[slug]/page.tsxOne dynamic segment: /blog/my-first-post
app/shop/[...slug]/page.tsxCatch-all: /shop/a and /shop/a/b, but not /shop
app/docs/[[...slug]]/page.tsxOptional catch-all that also matches /docs
app/(marketing)/page.tsxRoute group: organizes files and layouts without adding to the URL
app/blog/_components/Private folder that the router ignores
app/@sidebar/page.tsxParallel route slot passed to the parent layout as a prop
app/feed/(..)photo/[id]/page.tsxIntercepting route: show a parent-level route, for example as a modal
'use client'First line of a file: marks a client boundary; its imports join the client bundle
<Modal><Cart /></Modal>Pass a Server Component as children of a Client Component
import 'server-only'Build error if a module with secrets is imported into client code
NEXT_PUBLIC_API_URLOnly NEXT_PUBLIC_ variables reach the browser; others become empty strings there
const { id } = await paramsNext.js 15 and 16: params and searchParams are promises
const store = await cookies()cookies(), headers() and draftMode() are async; sync access is removed in 16
The previous model (no Cache Components) is documented at https://nextjs.org/docs/app/guides/caching-without-cache-components.
cacheComponents: true, partialPrefetching: truenext.config.ts options that turn on the Next.js 16 caching model
'use cache'; cacheLife('hours')Cache a function, component or page with a named lifetime profile
cacheTag('posts')Tag cached output so you can invalidate it later
revalidateTag('posts', 'max')Mark tagged entries stale and refresh them in the background (Next.js 16 signature)
updateTag(`user-${id}`)Server Actions only: expire a tag and read fresh data in the same request
revalidatePath('/profile')Invalidate cached data for one route path
await connection()Defer a component to request time before using random values or the current time
fetch(url, { cache: 'force-cache' })Previous model: opt one request into caching; fetch is uncached by default
fetch(url, { next: { revalidate: 3600, tags: ['user'] } })Previous model: cache for an hour and tag for on-demand invalidation
export const dynamic = 'force-dynamic'Previous model: render the route on every request
export const revalidate = 600Previous model: route-wide revalidation in seconds; must be a literal
Metadata rules are from https://nextjs.org/docs/app/getting-started/metadata-and-og-images; static params from https://nextjs.org/docs/app/api-reference/functions/generate-static-params.
export async function GET(request: Request) {}Route handler; GET, POST, PUT, PATCH, DELETE, HEAD and OPTIONS are supported
ctx: RouteContext<'/users/[id]'>Typed context for a handler; read await ctx.params
export const metadata: Metadata = { title, description }Static metadata from a layout or page; Server Components only
export async function generateMetadata({ params })Metadata that depends on data; wrap shared queries in React cache to fetch once
app/opengraph-image.tsxGenerate a social image with ImageResponse from next/og
export async function generateStaticParams() { return [{ slug: 'a' }] }Prerender listed dynamic paths at build time
export const dynamicParams = falseReturn 404 for paths not listed; only without Cache Components
return []Previous model: prerender every path on first visit; with Cache Components an empty list is a build error
Worked example: Cache a blog list and refresh it from a Server Action (Next.js 16)
With cacheComponents: true, this page puts the post list in the static shell, tags it, and refreshes it when an editor publishes:
// app/blog/page.tsx
import { cacheLife, cacheTag } from 'next/cache'
async function getPosts() {
'use cache'
cacheLife('hours')
cacheTag('posts')
return db.post.findMany({ orderBy: { createdAt: 'desc' } })
}
export default async function BlogPage() {
const posts = await getPosts()
return <ul>{posts.map((p) => <li key={p.id}>{p.title}</li>)}</ul>
}
// app/blog/actions.ts
'use server'
import { updateTag } from 'next/cache'
export async function publish(formData: FormData) {
await db.post.create({ data: { title: String(formData.get('title')) } })
updateTag('posts')
}
At build time getPosts runs once and its result goes into the prerendered HTML, so visitors get the list without a database round trip. The hours profile lets Next.js refresh it in the background over time. When publish runs, updateTag('posts') expires that entry and the editor's next render reads fresh data in the same request, so they see their post immediately. If you only need other visitors to catch up eventually, revalidateTag('posts', 'max') is the cheaper choice. On Next.js 15 without Cache Components, the equivalent is unstable_cache with tags: ['posts'] and revalidateTag('posts'). This is from the docs; we did not build it in a fresh app.
Common mistakes
Putting
'use client'at the top of a layout to make one button interactive.Move the button into its own file with the directive. The layout stays a Server Component and ships less JavaScript.
Reading
params.slugdirectly after upgrading to Next.js 15 or 16.paramsis a promise. Useconst { slug } = await params, or run the upgrade codemod withnpx @next/codemod@canary upgrade latest.Calling
revalidateTag('posts')with one argument on Next.js 16.The single-argument form is deprecated. Pass a profile such as
'max', or useupdateTaginside a Server Action for read-your-writes.Adding a
route.tsnext to apage.tsxin the same folder.They conflict. Put the handler under a separate segment such as
app/api/items/route.ts.Returning an empty array from
generateStaticParamsafter turning on Cache Components.That is now a build error. Return at least one real param, or follow the ISR with Cache Components guide for unknown params.
Keeping
middleware.tsafter upgrading to 16 and expecting the Node runtime.Rename it to
proxy.tsand the export toproxy. The old file still works for Edge but is deprecated.
Related cheat sheets
Sources
- https://nextjs.org/docs/app/getting-started/project-structure
- https://nextjs.org/docs/app/getting-started/server-and-client-components
- https://nextjs.org/docs/app/getting-started/caching
- https://nextjs.org/docs/app/guides/caching-without-cache-components
- https://nextjs.org/docs/app/getting-started/route-handlers
- https://nextjs.org/docs/app/getting-started/metadata-and-og-images
- https://nextjs.org/docs/app/api-reference/functions/generate-static-params
- https://nextjs.org/blog/next-16
- https://nextjs.org/blog
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.