Skip to content

Commit

Permalink
@remix-run/router: Add support for navigation blocking (#9709)
Browse files Browse the repository at this point in the history
* feat(router): add support for history blocking APIs
* feat(react-router): add `unstable_useBlocker` hook
* feat(react-router-dom): add `capture` option to `useBeforeUnload`

Co-authored-by: Matt Brophy <[email protected]>
  • Loading branch information
chaance and brophdawg11 authored Jan 13, 2023
1 parent 9640d01 commit bb7590a
Show file tree
Hide file tree
Showing 31 changed files with 4,622 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-needles-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-router-dom": patch
---

Added pass-through event listener options argument to `useBeforeUnload`
5 changes: 5 additions & 0 deletions .changeset/light-phones-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/router": minor
---

Added support for navigation blocking APIs
5 changes: 5 additions & 0 deletions .changeset/violet-timers-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-router-dom": minor
---

Add `unstable_useBlocker` hook for blocking navigations within the app's location origin
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ node_modules/
/packages/react-router-dom-v5-compat/react-router-dom

.eslintcache
/.env
/.env
/NOTES.md
5 changes: 5 additions & 0 deletions examples/navigation-blocking/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
4 changes: 4 additions & 0 deletions examples/navigation-blocking/.stackblitzrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"installDependencies": true,
"startCommand": "npm run dev"
}
15 changes: 15 additions & 0 deletions examples/navigation-blocking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Navigation Blocking
toc: false
order: 1
---

# Navigation Blocking

This example demonstrates using `unstable_useBlocker` to prevent navigating away from a page where you might lose user-entered form data. A potentially better UX for this is storing user-entered information in `sessionStorage` and pre-populating the form on return.

## Preview

Open this example on [StackBlitz](https://stackblitz.com):

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/remix-run/react-router/tree/main/examples/navigation-blocking?file=src/App.tsx)
12 changes: 12 additions & 0 deletions examples/navigation-blocking/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>React Router - Navigation Blocking</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading

0 comments on commit bb7590a

Please sign in to comment.