How SSG works in each router
Pages Router
Pages without data fetching are statically generated by default. When content depends on external data, the page exports getStaticProps. That function always runs on the server, never in the browser. It cannot read the incoming request, such as query parameters or HTTP headers. For each prerendered page, Next.js also writes a JSON file holding the getStaticProps result next to the HTML.
When the list of paths itself comes from external data, the page also exports getStaticPaths, usually together with getStaticProps. With fallback: false, any path not returned at build time returns a 404 page. The Next.js Static Generation docs show both functions in code.
App Router
generateStaticParams is the App Router replacement for getStaticPaths. It works with dynamic route segments to prerender routes at build time instead of on demand. The dynamicParams segment option defaults to true, so params not returned by generateStaticParams are rendered on demand. dynamicParams is not available when Cache Components is enabled (Next.js 16).
When to use SSG, and static export
The docs' test is whether the page can be prerendered before a user requests it. They list marketing pages, blog posts and portfolios, e-commerce product listings, and help and documentation as typical Static Generation pages. For how build-time HTML relates to search, see Next.js SEO.
Static export. Setting output: 'export' writes the site's HTML, CSS and JS to an out folder that any static host can serve. In a static export, App Router Server Components run during the build, like traditional static site generation. fallback: true does not work with a static export.
To review which routes on a live site could be prerendered, see Next.js performance optimization. For a full setup, see the guide to using Next.js as a static site generator.
Sources
- Static Site Generation (SSG) - Pages RouterNext.js · nextjs.org
- GlossaryNext.js · nextjs.org
- getStaticProps - Data Fetching (Pages Router)Next.js · nextjs.org
- getStaticPathsNext.js · nextjs.org
- generateStaticParams - API Reference (App Router)Next.js · nextjs.org
- Route Segment Config (App Router)Next.js · nextjs.org
- How to create a static export of your Next.js applicationNext.js · nextjs.org
- dynamicParamsNext.js · nextjs.org