What this thread does
Do first: call useBlocker with a predicate that combines dirty state with a changed destination pathname, inside the route rendered by your data router.
Short answer
As of November 2026, React Router 8.5.2, released November 18, provides useBlocker for SPA navigation. It does not intercept hard reloads or cross-origin navigation (API). Choose what save success means: proceed() resumes the pending destination; reset() cancels it and stays on this page. Neither method saves the form.
Choose / don't choose
- Save then leave: proceed only after the save reports success; don't clear edits at submission time.
- Save and stay: reset the blocked navigation after success, then present the clean form (guide).
- Same pathname changes: exclude them only if query/hash changes cannot discard edits; otherwise adapt the predicate. This is application policy based on the API's current/next location arguments.
Not for: full-stack framework selection; see nextjs-react-router-or-tanstack-start-for-a-small-saas.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
shouldBlock | Return value !== "" && currentLocation.pathname !== nextLocation.pathname; value is application state | React Router 8.5.2 docs | Predicate example |
| Data router | Create once outside the React tree with the route objects containing the form | Data mode, current docs | Installation |
RouterProvider | Pass that router as router; import from react-router/dom in the documented DOM entry point | Data mode, current docs | Installation |
blocker.proceed() | Call only while blocker.state === "blocked", after confirmed success or explicit leave | Current blocker API | API |
blocker.reset() | Cancel the pending navigation; state returns to unblocked, location stays current | Current blocker API | API |
fetcher.data?.ok | Condition guarding blocker.reset() in the example | Current navigation guide | Success effect |
Order of operations
1. Pass the data router to RouterProvider; track dirty edits and show confirmation while navigation is blocked (installation, guide). 2. Submit the save without clearing the draft or resolving the blocker. On a failed save, retain both the dirty data and pending blocked state. This follows the guide's success-only resolution condition, rather than treating any completed request as success. 3. When the intended save succeeds, update the saved baseline / clear dirty state. If the current blocker is still blocked and the chosen policy is leave, call blocker.proceed() for that pending destination (API example, success alternative). 4. For stay, call blocker.reset() and clear/reset the saved form as appropriate. A controlled form also needs its owning state updated; a DOM form reset alone does not choose the application's dirty baseline.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
blocked persists after a save (state/symptom) | The blocked navigation needs reset or proceed | Handle successful action data with reset or proceed according to the chosen flow | Guide |
| Browser reload bypasses confirmation (symptom) | Hard reloads and cross-origin navigations are not handled | Treat document-exit behavior separately; don't claim useBlocker protects it | API |
callmeberzerker's October 16, 2021 issue records the earlier missing-hook problem. The current documented API replaces historical router-internals workarounds.
Missing
- The guide's
okfield is an example contract. Define save success, validation errors and request identity for the application; do not act on stale success from an earlier submission. - No universal exception text is asserted for the two lifecycle symptoms.
Checked
2026-11-24; React Router 8.5.2. Sources read: dated changelog, blocker API, navigation guide, data installation and callmeberzerker's dated report. No navigation or save requests were executed.
Started from a post by @React Router, packaged by the editor. Original post