Next.jsHard
What is the difference between fallback: false, true, and blocking in getStaticPaths?
fallback controls what happens when someone requests a dynamic path that was not prerendered: false returns a 404, true serves a loading version immediately and fills it in on the client, and "blocking" renders the page on the server before responding. With true and "blocking", the generated page is cached for future visitors.
fallback: false
- Only the listed paths exist; anything else is a 404.
- Best for small, known sets (a few docs pages, fixed categories).
- New content requires a rebuild.
fallback: true
- The first visitor gets a static "fallback" version of the page with empty props instantly.
router.isFallbackistrue; you must render a loading state.- Next.js runs
getStaticPropsin the background and the page swaps in the data. - Later visitors get the fully generated page.
- Crawlers receive the complete page.
- Use it for very large sites where fast first byte matters, but it adds UI complexity.
fallback: "blocking"
- The first visitor waits while the server renders the page, like SSR, then the result is cached.
- No loading state to handle, no
isFallback. - The most common choice and the closest to App Router behavior without Cache Components.
Interaction with notFound
With true or "blocking", return { notFound: true } from getStaticProps for IDs that do not exist, otherwise any URL generates a page.
App Router mapping
falsemaps toexport const dynamicParams = false(without Cache Components)."blocking"is the default without Cache Components.- With Cache Components, unknown params get the App Shell first and the full page is generated in the background, which resembles
truewithout the manualisFallbackhandling.
Code example
tsx
1// pages/products/[id].tsx2import { useRouter } from "next/router";3import type { GetStaticPaths, GetStaticProps } from "next";45export const getStaticPaths: GetStaticPaths = async () => ({6 paths: [{ params: { id: "1" } }, { params: { id: "2" } }],7 fallback: true, // try false | true | "blocking"8});910export const getStaticProps: GetStaticProps = async ({ params }) => {11 const res = await fetch(`https://api.example.com/products/${params!.id}`);12 if (!res.ok) return { notFound: true }; // stop unknown ids becoming pages13 return { props: { product: await res.json() }, revalidate: 60 };14};1516export default function Product({ product }: { product?: { name: string } }) {17 const router = useRouter();1819 // Only needed with fallback: true20 if (router.isFallback) return <p>Loading product…</p>;2122 return <h1>{product!.name}</h1>;23}
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.