next.js
4f350fb3 - docs: read the URL in history API event handlers instead of calling hooks (#101224)

Commit
23 days ago
docs: read the URL in history API event handlers instead of calling hooks (#101224) ## Summary The `pushState` and `replaceState` examples in Linking and Navigating and the Single-Page Applications guide called `useSearchParams()` or `usePathname()` during render, but only used the value inside a click handler. That makes the component depend on the request URL, so with Cache Components it needs a Suspense boundary, and without Cache Components it is client-rendered up to the nearest one, for buttons that render nothing URL-dependent. The examples now read `window.location.search` / `window.location.pathname` inside the handler and drop the hook. The lead-in sentence on both pages now says when to use each, and links to the `useSearchParams` prerendering section. - docs: read the URL in history API event handlers instead of calling hooks - docs: point handler-only URL reads at window.location - docs: name the hooks in the window.location guidance <!-- NEXT_JS_LLM -->
Author
Parents
Loading