Capítulo 378 de 456
getStaticPaths, exported from a dynamic-route page, tells Next.js which paths to statically prerender at build time, and how to handle paths not in that list via fallback.
paths: array of { params: {...}, locale? } objects; params keys must match the dynamic segment names (including arrays for catch-all routes, null/[]/false for optional catch-all root).fallback: false: any path not returned results in a 404; must re-run next build to add paths.fallback: true: ungenerated paths serve a fallback UI first (router.isFallback === true), then swap to the real page once getStaticProps finishes in the background; client-side navigations instead behave like 'blocking'.fallback: 'blocking': ungenerated paths SSR on first request (like SSR), then are cached for subsequent requests; no fallback flash.router.isFallback: from useRouter, detects the fallback render state.params case sensitivity: values are case-sensitive and should be normalized.export const getStaticPaths = (async () => {
return {
paths: [{ params: { name: 'next.js' } }],
fallback: true, // false or "blocking"
}
}) satisfies GetStaticPaths
getStaticPaths shape with fallback: true.export async function getStaticPaths() {
const res = await fetch('https://.../posts')
const posts = await res.json()
const paths = posts.map((post) => ({ params: { id: post.id } }))
return { paths, fallback: false }
}
fallback: false.import { useRouter } from 'next/router'
function Post({ post }) {
const router = useRouter()
if (router.isFallback) return <div>Loading...</div>
// Render post...
}
fallback: true regenerates a page.fallback value | Ungenerated path behavior | Client-side nav behavior | Updates existing pages? |
|---|---|---|---|
false | 404 | 404 | No — needs rebuild |
true | fallback UI, then swap once ready | acts like 'blocking' | No — pair with ISR revalidate |
'blocking' | SSR on first request, then cached | SSR on first request | No — pair with ISR revalidate |
fallback: true/'blocking' with output: 'export': not supported for static exports.fallback: true/'blocking' to auto-update pages: they only generate missing pages once; use Incremental Static Regeneration (revalidate) to refresh existing ones.params casing: WoRLD only matches the literal path WoRLD, not world.fallback: false for small, rarely-changing path sets; true/'blocking' for very large catalogs where prebuilding everything is too slow.'blocking'-like SSR behavior even under fallback: true.getStaticPaths with a corresponding getStaticProps on the same page.generateStaticParams() is the stable successor since v13.4.0.router.isFallback.