Pages navigation and fallback
What you need to know
Pages Router navigation uses next/router when programmatic control is needed. getStaticPaths chooses which dynamic routes are built and what happens for paths not in that initial list.
By the end, you can: use next/router correctly; explain getStaticPaths choices.
Generate known book details and block on new paths
// pages/catalog/[slug].tsximport type { GetStaticPaths, GetStaticProps, InferGetStaticPropsType } from 'next';const titles:Record<string,string> = {'fern-atlas':'Fern Atlas','river-walk':'River Walk'};export const getStaticPaths = (async () => ({paths:[{params:{slug:'fern-atlas'}}],fallback:'blocking'})) satisfies GetStaticPaths;export const getStaticProps = (async ({params}) => { const slug=params?.slug; if(typeof slug!=='string'||!Object.hasOwn(titles,slug)) return {notFound:true}; return {props:{title:titles[slug]},revalidate:120};}) satisfies GetStaticProps<{title:string}>;export default function Book({title}:InferGetStaticPropsType<typeof getStaticProps>){return <main><h1>{title}</h1></main>;}Expected behavior: Fern Atlas is built initially; River Walk can be generated on the first request. Unknown slugs should produce not-found.
How it works
Use Link for normal links. In Pages Router, useRouter imported from next/router supplies pathname, query, asPath and readiness information. Query values may be absent on initial automatic-static rendering and can be strings or arrays. Use isReady in effects when needed rather than conditionally changing the initial server HTML. Do not pass an arbitrary URL to router.push. For dynamic static pages, getStaticPaths returns paths plus fallback. false restricts the route to known generated paths; true allows on-demand generation with a fallback UI for eligible direct requests, while crawlers and client navigation can receive blocking-like behavior; blocking waits for initial generation before responding. Both on-demand modes may cache generated paths. In fallback:true, handle router.isFallback before reading props. Missing records can return notFound from getStaticProps. A fallback mode is not a permission rule. Static export does not support on-demand fallback modes.
Read route state after client readiness
import {useEffect,useState} from 'react';import {useRouter} from 'next/router';export default function Selection(){ const router=useRouter(); const [label,setLabel]=useState(''); useEffect(()=>{if(router.isReady){const v=router.query.view;setLabel(v==='compact'?'Compact':'Comfortable');}},[router.isReady,router.query.view]); return <p>{label || 'Reading preference'}</p>;}Expected behavior: Initial markup is stable. After readiness, the displayed preference is normalized to one of two labels.
Common mistake
Do not import next/navigation useRouter into a Pages-only component or assume fallback:true always sends a skeleton. Handle unknown slugs and array query values intentionally.
Practice and verification
Create a path matrix for fern-atlas, river-walk and missing under all three fallback modes. Compare first direct load, client navigation and repeat requests with an approved production build.
Scope: Proposed Next.js 16.x, React 19, Node runtime. Root-mounted Pages and mixed-router fixtures with Cache Components disabled; the basePath example is separate. Framework examples are staged, not executed. Exact patched dependencies and platform contracts pending.