Next.js essentials: 50 cards on the App Router and caching
Next.js App Router basics: server vs client components, layouts, route handlers, server actions, caching, metadata, dynamic routes and middleware.
Practice now
Study without an account
Scheduled with the default Askesis timings. Progress is saved in this browser.
All 50 cards
- 1What is the App Router?Next.js’s router in the
app/directory: folders map to URL segments, special files likepage.tsxandlayout.tsxdefine the UI, and components are React Server Components by defaultThe older Pages Router (pages/) is still supported. - 2Which file makes a folder a public route?
page.tsx(or.js,.jsx,.ts); without one the folder isn’t routable, so other files can be colocated safely - 3Which URL does
app/blog/[slug]/page.tsxserve?/blog/:slug, e.g./blog/hello-worldwithslugset to"hello-world" - 4Read a dynamic route parameter in a pagetsx
// app/blog/[slug]/page.tsx export default async function Page({ params, }: { params: Promise<{ slug: string }> }) { const { slug } = await params return <h1>{slug}</h1> }paramsbecame a Promise in Next.js 15, and Next.js 16 removed synchronous access. - 5
[...slug]vs[[...slug]]app/docs/[...slug]matches/docs/a/b(slug=["a", "b"]) but not/docs; the optional[[...slug]]also matches/docs - 6What is a folder named
(marketing)?A route group: it organizes routes or gives them a shared layout without adding a segment to the URLFolders starting with an underscore, like_components, are private and never become routes. - 7Are App Router components server or client components by default?Server Components, unless their module has
'use client'or is imported from a module that does - 8What can Server Components do that Client Components can’t?Be
async, read databases, files and secrets directly, and keep their code and dependencies out of the browser bundleIn exchange, they can’t use state, effects, event handlers or browser APIs. - 9When does a component need
'use client'?When it uses state or effects (useState,useEffect), event handlers likeonClick, browser APIs likelocalStorage, or hooks built on them - 10Where should
'use client'go?At the very top of the file, before imports. Everything that module imports becomes client code, so put it on small interactive leaf components, not whole pages - 11Are Client Components rendered on the server?Yes. They are prerendered to HTML for the first load and then hydrated in the browser;
'use client'means the code also ships to the browser, not that it only runs there - 12How can a Client Component display a Server Component?Pass the Server Component as
children(or another prop) from a server parent; a client module can’t import a Server Componenttsx// app/page.tsx (server) <Modal> <Cart /> {/* still a Server Component */} </Modal> - 13What props can a Server Component pass to a Client Component?Only serializable values: strings, numbers, plain objects, arrays, Dates, Promises and the like; not functions or class instances, except Server Actions
- 14What does
import 'server-only'do?Makes the build fail if client code imports that module, so secrets and server logic can’t leak into the browser bundle - 15Which environment variables reach the browser?Only those prefixed with
NEXT_PUBLIC_; they are inlined into the JavaScript at build time. All others stay on the server - 16What does
layout.tsxdo?Wraps a segment and its children (through thechildrenprop) with shared UI; it keeps its state and doesn’t re-render when navigating between those child pages - 17What must the root layout contain?
app/layout.tsxis required and must render the<html>and<body>tags - 18
template.tsxvslayout.tsxA template also wraps child routes, but it remounts on every navigation, so state resets and effects run again - 19What does
loading.tsxdo?Wraps the segment’s page in a React Suspense boundary and shows instantly while the page’s content streams in - 20What does
error.tsxdo, and what must it be?An error boundary for its segment that renders a fallback with a way to retry; it must be a Client Component ('use client')Errors thrown in the root layout needglobal-error.tsx. - 21What does calling
notFound()do?Stops rendering and shows the nearestnot-found.tsxwith a 404 status; it comes fromnext/navigation - 22Write a route handlertsx
// app/api/users/route.ts export async function GET() { const users = await db.user.findMany() return Response.json(users) } export async function POST(request: Request) { const data = await request.json() return Response.json(await db.user.create({ data }), { status: 201 }) }Export one function per HTTP method. - 23Can
page.tsxandroute.tsshare a folder?No. A segment is either a page or an endpoint; put handlers under their own path, such asapp/api/… - 24Are GET route handlers cached by default?Not since Next.js 15 (they were in 14). Opt in with
export const dynamic = 'force-static' - 25Create a post with a Server Actiontsx
export default function NewPost() { async function create(formData: FormData) { 'use server' await db.post.create({ data: { title: String(formData.get('title')) } }) revalidatePath('/posts') } return ( <form action={create}> <input name="title" /> <button>Save</button> </form> ) }The form works even before JavaScript loads; Server Actions are called with POST requests. - 26Why must every Server Action check auth and validate input?Each action is exposed as a public POST endpoint that anyone can call directly, not only through your form
- 27Can you define a Server Action inside a Client Component?No. Put
'use server'at the top of a separate file and import the action from there, or receive it as a prop - 28Is
fetchcached by default in a Server Component?Not since Next.js 15. Opt in per request with{ cache: 'force-cache' }or{ next: { revalidate: 3600 } }Next.js 14 cachedfetchby default, which surprised many people. - 29What does
export const revalidate = 3600do in a page?Time-based revalidation (ISR): the page is served from cache and regenerated in the background once it’s older than an hourPer request:fetch(url, { next: { revalidate: 3600 } }). - 30Refresh cached data right after a mutationCall
revalidatePath('/posts'), orrevalidateTag('posts', 'max')for data fetched with{ next: { tags: ['posts'] } }The secondcacheLifeprofile argument torevalidateTagis new in Next.js 16; in Server Actions,updateTaggives read-your-own-writes. - 31What does the
'use cache'directive do?With Cache Components enabled (cacheComponents: true, Next.js 16), it marks a function, component or route as cacheable;cacheLife()sets how long andcacheTag()tags ittsxasync function getPosts() { 'use cache' cacheLife('hours') return db.post.findMany() } - 32What is request memoization?Identical
fetchGET requests (same URL and options) made during one server render run only once; wrap other data functions in React’scache()for the same effect - 33Static vs dynamic renderingRoutes are prerendered at build time by default; they render per request when they read request data like
cookies(),headers()orsearchParams, or use uncached dataWith Cache Components, a route can mix both: a prerendered shell with dynamic parts streamed inside<Suspense>. - 34Prerender every blog post at build timetsx
// app/blog/[slug]/page.tsx export async function generateStaticParams() { const posts = await getPosts() return posts.map((post) => ({ slug: post.slug })) } - 35Read a cookie in a Server Componenttsx
import { cookies } from 'next/headers' const theme = (await cookies()).get('theme')?.valuecookies()andheaders()are async since Next.js 15 and make the route dynamic. Setting cookies only works in Server Actions and route handlers. - 36Read the query string
?page=2in a pagetsxexport default async function Page({ searchParams, }: { searchParams: Promise<{ page?: string }> }) { const { page = '1' } = await searchParams }ReadingsearchParamsmakes the page render per request. - 37Set a page’s title and descriptiontsx
import type { Metadata } from 'next' export const metadata: Metadata = { title: 'Pricing', description: 'Plans for teams of every size', }Export it from apageorlayout; metadata only works in Server Components. - 38Generate metadata from fetched datatsx
export async function generateMetadata({ params }: Props): Promise<Metadata> { const { slug } = await params const post = await getPost(slug) return { title: post.title } }Fetches shared with the page are deduplicated. - 39What is the page title?tsx
// app/layout.tsx title: { template: '%s | Acme', default: 'Acme' } // app/pricing/page.tsx title: 'Pricing'Pricing | Acme; pages without a title fall back toAcme - 40Which special files generate metadata?
favicon.ico,icon.png,opengraph-image.png(or.tsx),sitemap.tsandrobots.tsinapp/; Next.js adds the tags and routes - 41Redirect logged-out users with middlewaretsx
// middleware.ts (proxy.ts in Next.js 16) import { NextResponse, type NextRequest } from 'next/server' export function middleware(request: NextRequest) { if (!request.cookies.has('session')) { return NextResponse.redirect(new URL('/login', request.url)) } } export const config = { matcher: ['/dashboard/:path*'] }Middleware runs before the route; returning nothing lets the request continue. - 42What happened to
middleware.tsin Next.js 16?It was renamed toproxy.tswith an exportedproxyfunction that runs on the Node.js runtime;middleware.tsstill works for the Edge runtime but is deprecated - 43Is middleware enough to protect private pages?No. Treat it as an optimistic check and verify auth again next to the data: in Server Components, Server Actions and route handlersCVE-2025-29927 (March 2025) let a crafted header skip middleware entirely on unpatched versions.
- 44What does
<Link>fromnext/linkadd over<a>?Client-side navigation without a full page reload, and in production it prefetches routes as their links enter the viewport - 45Where do you import
useRouterfrom in the App Router?next/navigation, notnext/router(that’s the Pages Router).usePathnameanduseSearchParamslive there too; all are Client Component hooks - 46What is special about
redirect()?It throws a special error to stop rendering, so code after it never runs; call it outsidetry/catchblocksredirectfromnext/navigationworks in Server Components, Server Actions and route handlers. - 47Why might
useSearchParams()break the production build?On a statically rendered route, the Client Component calling it must be inside a<Suspense>boundary; otherwise the build fails with a missing Suspense boundary error - 48What does
next/imagedo?<Image>resizes images on demand, serves modern formats like WebP (AVIF can be enabled), lazy-loads by default and reserves space to avoid layout shiftRemote images needwidthandheight(orfill) and an allowed host inimages.remotePatterns. - 49How do you stream a slow part of a page?Wrap the slow async component in
<Suspense fallback={…}>: the rest of the page is sent at once and that part streams in when its data is ready - 50What is a folder named
@modal?A parallel route slot: its page renders alongside the main page and reaches the parent layout as amodalpropCombined with intercepting routes like(.)photo/[id], it powers modals that keep a shareable URL.
Frequently asked questions
Which Next.js version does this deck cover?
The App Router as of Next.js 15 and 16, with notes where they differ from Next.js 14, such as fetch caching defaults and async params.
Does it cover the Pages Router?
No. It focuses on the App Router, which is the recommended way to build new Next.js apps. getServerSideProps and other Pages Router APIs aren’t included.
Should I learn React first?
Yes. Next.js builds on React, so components, props, state and hooks should feel familiar. Our React deck covers those basics.
Is middleware still a thing in Next.js 16?
It was renamed to proxy and now runs on the Node.js runtime. The old middleware file still works for Edge use cases but is deprecated.
More in Web development
HTML & CSS
Fifty HTML and CSS cards: semantic HTML and accessible forms, specificity and cascade layers, flexbox and grid, stacking contexts and z-index, modern units and container queries.
50 cardsReact
Fifty React cards: state and re-rendering, useEffect and cleanup, memoization, refs, context, Suspense and the React 19 APIs like use, useOptimistic and useActionState.
50 cardsVue
Vue 3 fundamentals: ref vs reactive, computed and watch, props and emits, v-model, directives, slots, single-file components and Pinia stores.
50 cardsAngular
Modern Angular: standalone components, signals, inputs and outputs, dependency injection, RxJS basics, @if and @for, routing and OnPush change detection.
50 cardsNode.js
Node.js fundamentals: the event loop, ESM vs CommonJS, npm, streams, Buffer, fs/promises, process, error handling, worker threads and a basic HTTP server.
50 cardsGraphQL
GraphQL basics: schema types, queries, mutations, subscriptions, resolvers, variables, fragments, N+1 and DataLoader, introspection and GraphQL vs REST.
50 cards