Skip to content

Commit 5bd29ad

Browse files
authored
Migrate and upgrade react router to v7 (#183)
* react-router v7 support * Add beta version * Update peer dependencies * Bump version to 0.8.0
1 parent 0a5dae2 commit 5bd29ad

File tree

8 files changed

+77
-63
lines changed

8 files changed

+77
-63
lines changed

README.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# react-router-prompt 🚨
22

3-
> A component for the react-router 6 `Prompt`. Allows to create more flexible dialogs.
3+
> A component for the react-router-dom 6 / react-router 7 `Prompt`. Allows to create more flexible dialogs.
4+
5+
Please follow [Note section](https://github.com/sshyam-gupta/react-router-prompt#note) for more details on react-router support
46

57
[![npm version](https://img.shields.io/npm/v/react-router-prompt.svg)](https://www.npmjs.com/package/react-router-prompt)
68

@@ -16,7 +18,7 @@
1618

1719
### Prerequisite
1820

19-
**React-router-dom >= 6.19** and can be used only with [**data routers**](https://reactrouter.com/en/6.8.1/routers/picking-a-router#using-v64-data-apis)
21+
**React-router-dom >= 7** and shall be ideally used with [**data routers**](https://reactrouter.com/6.28.1/routers/picking-a-router#using-v64-data-apis)
2022

2123
```bash
2224
pnpm add react-router-prompt
@@ -69,12 +71,15 @@ yarn add react-router-prompt
6971
7072
#### Note 🗒️
7173
72-
This version works with react-router-dom >=v6.19
73-
Should be used within [data routers](https://reactrouter.com/en/6.8.1/routers/picking-a-router#using-v64-data-apis)
74+
This version works with react-router-dom >=v7 or react-router >=v7 and shall be ideally used with [**data routers**](https://reactrouter.com/6.28.1/routers/picking-a-router#using-v64-data-apis)
75+
76+
- For react-router support `(v7)` please install `v0.8.x`
77+
78+
- For react-router-dom support `(v6.19.x - v6.28.1)` please install `v0.7.x`
7479
75-
For react-router support `(v6 - v6.2.x)` please install v0.3.0
80+
- For react-router-dom support `(v6.7.x - v6.18.x)` please install `v0.5.4`
7681
77-
For react-router support (v6.7.x - v6.18.x) please install v0.5.4
82+
- For react-router-dom support `(v6 - v6.2.x)` please install `v0.3.0`
7883
7984
_Skipped support in middle due to breaking changes on react-router apis_
8085

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.7.3",
2+
"version": "0.8.0",
33
"name": "react-router-prompt",
44
"description": "React Router Navigation Prompt for v6",
55
"type": "module",
@@ -60,7 +60,7 @@
6060
"prettier": "^3.4.2",
6161
"react": "^19.0.0",
6262
"react-dom": "^19.0.0",
63-
"react-router-dom": "^6.22.1",
63+
"react-router": "^7.1.1",
6464
"size-limit": "^11.0.2",
6565
"typescript": "^5.3.3",
6666
"vite": "^6.0.5",
@@ -70,7 +70,7 @@
7070
"peerDependencies": {
7171
"react": ">=16.8",
7272
"react-dom": ">=16.8",
73-
"react-router-dom": ">=6.19 <7"
73+
"react-router": ">=7"
7474
},
7575
"size-limit": [
7676
{

pnpm-lock.yaml

+38-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hooks/use-confirm.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BlockerFunction, Location } from "react-router-dom"
1+
import { BlockerFunction, Location } from "react-router"
22
import usePrompt from "./use-prompt"
33
import { useState } from "react"
44

src/hooks/use-prompt.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
Blocker,
66
BlockerFunction,
77
Location,
8-
} from "react-router-dom"
8+
} from "react-router"
99

1010
// You can abstract `useBlocker` to use the browser's `window.confirm` dialog to
1111
// determine whether or not the user should navigate within the current origin.

src/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useCallback } from "react"
2-
import { BlockerFunction, Location } from "react-router-dom"
2+
import { BlockerFunction, Location } from "react-router"
33

44
import useConfirm from "./hooks/use-confirm"
55
import usePrompt from "./hooks/use-prompt"

src/main.tsx

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import React, { useState } from "react"
22
import ReactDOM from "react-dom/client"
3-
import {
4-
createBrowserRouter,
5-
RouterProvider,
6-
NavLink,
7-
Outlet,
8-
} from "react-router-dom"
3+
import { createBrowserRouter, RouterProvider, Outlet, Link } from "react-router"
94

105
import ReactRouterPrompt from "."
116

@@ -32,7 +27,7 @@ function Form() {
3227
<ReactRouterPrompt
3328
when={() => input.length >= 1}
3429
beforeConfirm={async () => {
35-
await delayPromise()
30+
// await delayPromise()
3631
await fetch("https://api.zippopotam.us/in/400072")
3732
.then((response) => response.text())
3833
.then((result) => console.log(result))
@@ -75,9 +70,9 @@ function Root() {
7570
return (
7671
<div>
7772
<nav>
78-
<NavLink to="/">Home</NavLink>
73+
<Link to="/">Home</Link>
7974
&nbsp;&nbsp;&nbsp;
80-
<NavLink to="/promptable">Prompt</NavLink>
75+
<Link to="/promptable">Prompt</Link>
8176
</nav>
8277
<Outlet />
8378
</div>

vite.config.ts

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { resolve } from "path";
2-
import dts from "vite-plugin-dts";
3-
import tsConfigPaths from "vite-tsconfig-paths";
4-
import * as packageJson from "./package.json";
1+
import { resolve } from "path"
2+
import dts from "vite-plugin-dts"
3+
import tsConfigPaths from "vite-tsconfig-paths"
4+
import * as packageJson from "./package.json"
55

6-
import { defineConfig } from "vite";
7-
import react from "@vitejs/plugin-react-swc";
6+
import { defineConfig } from "vite"
7+
import react from "@vitejs/plugin-react-swc"
88

99
// https://vitejs.dev/config/
1010
export default defineConfig({
@@ -22,15 +22,19 @@ export default defineConfig({
2222
fileName: "react-router-prompt",
2323
},
2424
rollupOptions: {
25-
external: [...Object.keys(packageJson.peerDependencies), 'react/jsx-runtime'],
25+
external: [
26+
...Object.keys(packageJson.peerDependencies),
27+
"react/jsx-runtime"
28+
],
2629
output: {
30+
exports: "named",
2731
globals: {
28-
'react': 'react',
29-
'react-dom': 'ReactDOM',
30-
'react-router-dom': 'reactRouterDom',
31-
'react/jsx-runtime': 'react/jsx-runtime',
32+
react: "react",
33+
"react-dom": "ReactDOM",
34+
"react-router": "reactRouter",
35+
"react/jsx-runtime": "react/jsx-runtime",
3236
},
33-
}
37+
},
3438
},
35-
}
36-
});
39+
},
40+
})

0 commit comments

Comments
 (0)