🌍 NextJS · flashcards
NextJS Advanced Features Flashcards
50 question-and-answer cards covering Advanced Features as it is examined in NextJS. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.
24 sample cards from the Advanced Features deck
Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.
How do you limit which paths Middleware runs on?
Export a config object with a matcher, e.g. export const config = { matcher: '/about/:path*' } or an array of paths. Only matching requests invoke the middleware.
What are the common actions Middleware can perform on a request?
Rewrite (NextResponse.rewrite), redirect (NextResponse.redirect), continue with modifications (NextResponse.next), set request/response headers, and read/set cookies. It is commonly used for auth, A/B testing, i18n, and geolocation.
Why must Next.js Middleware avoid heavy computation or Node-specific APIs?
Middleware runs on the Edge Runtime, a lightweight environment that does not support all Node.js APIs and is optimized for low latency. Heavy or Node-only operations can fail or slow every request, so keep middleware fast and lean.
How do you return a redirect from Middleware?
Import NextResponse and return NextResponse.redirect(new URL('/login', request.url)). This sends the client to a new URL before the request reaches the destination route.
What is the difference between NextResponse.rewrite and NextResponse.redirect in Middleware?
redirect changes the URL the browser navigates to (client sees the new URL, extra round trip). rewrite serves content from a different path while keeping the original URL in the address bar (proxy-like, transparent to the user).
In an API route, how do you read the request body and query parameters?
Use req.body for the parsed body (JSON/form data auto-parsed by the built-in body parser) and req.query for query string plus dynamic route parameters. Both are objects.
How do you send a JSON response with a specific status code in a Next.js API route?
Chain the methods: res.status(201).json({ message: 'Created' }). res.status sets the HTTP status and returns res, so json can be chained to serialize and send the body.
How do you disable or configure the built-in body parser in a Next.js API route?
Export a config object from the route, e.g. export const config = { api: { bodyParser: false } } to handle raw bodies (like webhooks/file uploads), or set bodyParser: { sizeLimit: '1mb' } to change the limit.
What is a dynamic route in Next.js and how is it created?
A dynamic route matches variable path segments using square brackets in the filename, e.g. pages/posts/[id].js matches /posts/1, /posts/2, etc. The bracketed name becomes a param available in query and getStaticPaths/getServerSideProps params.
How do dynamic routes with getStaticPaths work together for pre-rendering?
For pages/posts/[id].js you export getStaticPaths returning the list of ids to pre-render (paths) and a fallback strategy, and getStaticProps which receives context.params.id to fetch that post's data at build time.
How do you access the dynamic route parameter inside getStaticProps?
Read it from the context params object: export async function getStaticProps({ params }) { const id = params.id; ... }. The param name matches the bracketed segment in the filename.
What is a catch-all route in Next.js and how is it written?
A catch-all route uses three dots inside brackets, e.g. pages/posts/[...slug].js. It matches any number of path segments after /posts/, such as /posts/a, /posts/a/b, /posts/a/b/c.
What form does the param take for a catch-all route [...slug]?
The param becomes an array of the matched segments. For /posts/a/b/c, params.slug is ['a', 'b', 'c']. Even a single segment /posts/a yields params.slug = ['a'].
Does a catch-all route [...slug] match the base path /posts (with no segments)?
No. A standard catch-all route requires at least one segment, so /posts (the parent path) is NOT matched and returns 404. Use an optional catch-all route to match the base path too.
What is an optional catch-all route and how is it written?
An optional catch-all route uses double brackets with three dots, e.g. pages/posts/[[...slug]].js. It behaves like a catch-all but ALSO matches the base route /posts with no parameters.
What is params.slug for an optional catch-all route [[...slug]] when the base path /posts is requested?
When no segments are present (i.e. /posts), params is empty and params.slug is undefined. With segments it is an array like ['a', 'b'], identical to a normal catch-all.
Summarize the difference between [id], [...slug], and [[...slug]] routes.
[id] matches exactly one segment (param is a string). [...slug] matches one or more segments (param is an array), but not the base path. [[...slug]] matches zero or more segments (param array or undefined), including the base path.
How do you build getStaticPaths paths for a catch-all route [...slug]?
Each params value must be an array of strings, e.g. paths: [ { params: { slug: ['a', 'b'] } }, { params: { slug: ['a'] } } ]. The array elements correspond to the path segments.
Can you use getServerSideProps with dynamic and catch-all routes?
Yes. getServerSideProps receives context.params where the dynamic segment is a string (for [id]) or an array (for [...slug] / [[...slug]]). getStaticPaths is not used with getServerSideProps since paths are resolved per request.
What is the return option 'notFound' used for in getStaticProps/getServerSideProps?
Returning { notFound: true } makes the page return a 404 status and render the 404 page, even if the route matched. It is used when requested data does not exist.
What is the 'redirect' return option in getStaticProps/getServerSideProps?
Returning { redirect: { destination: '/login', permanent: false } } sends the user to another route. permanent: true uses a 308 (permanent) redirect; false uses a 307 (temporary) redirect for SEO signaling.
For which routing/data method is the client informed of a loading state, and how is it checked?
With getStaticPaths fallback: true, a not-yet-generated page shows a loading fallback. It is checked via useRouter().isFallback, which is true while getStaticProps runs in the background and false once real props arrive.
Why can't you import getStaticProps or getServerSideProps data-fetching code that uses server-only modules into client components?
getStaticProps and getServerSideProps run only on the server and are stripped from the client bundle by Next.js. You can safely use server-only modules (fs, database drivers, secrets) inside them, but that code must not be imported into client-rendered components.
Which advanced feature would you choose for a blog with thousands of posts that update occasionally: SSG with fallback, pure SSR, or client-side fetching, and why?
SSG with getStaticPaths (fallback: true or 'blocking') plus ISR (revalidate). It pre-renders popular posts at build time, generates others on demand, and periodically revalidates content, giving fast static delivery with fresh data and good SEO without rebuilding for every post.
What this deck covers
The Advanced Features deck follows the NextJS Advanced Features syllabus — 3 chapters and 10 topics — so questions land on material that is genuinely examinable rather than trivia around it. That works out to roughly 16.7 cards per chapter.
Answers are written to be recallable, not just readable — averaging about 202 characters, which is long enough to carry the reasoning and short enough to say out loud.
A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.
Advanced Features flashcards FAQ
How many Advanced Features flashcards are in this NextJS deck?
50 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.
Are these NextJS flashcards free?
Yes. The preview here is free to read with no signup, and the full 50-card deck is free inside the Examius app.
What do the Advanced Features cards cover?
They follow the NextJS Advanced Features syllabus — 3 chapters and 10 topics — so the questions track what is actually examinable.
How should I use these flashcards?
Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.