React Router Navigation Prompt for v7
npm install react-router-prompt
A Component for the react-router v7 Prompt (package renamed from react-router-dom). Allows to create more flexible dialogs.
Please follow Note section for more details on react-router support
React-router >= 7 and shall be ideally used with data routers
``bash`
pnpm add react-router-prompt
or with other package manager like yarn
`bash`
yarn add react-router-prompt
` Do you really want to leave?jsx`
{({ isActive, onConfirm, onCancel }) => (
)}
1. when: boolean | BlockerFunction
`ts`
BlockerFunction = (args: {
currentLocation: Location
nextLocation: Location
historyAction: HistoryAction
}) => boolean
2. beforeConfirm(nextLocation?: Location) : Promise _(Optional)_
3. beforeCancel() : Promise _(Optional)_
1. isActive: BooleanonConfirm(nextLocation?: Location)
2. : voidonCancel()
3. : voidnextLocation
4. : Location | undefined
#### Note 🗒️
This version works with react-router >=v7 and shall be ideally used with data routers
- For react-router support (v7) please install v0.8.x
- For react-router-dom support (v6.19.x - v6.28.1) please install v0.7.x
- For react-router-dom support (v6.7.x - v6.18.x) please install v0.5.4
- For react-router-dom support (v6 - v6.2.x) please install v0.3.0`
_Skipped support in middle due to breaking changes on react-router apis_
Contributions, issues and feature requests are always welcome!
Feel free to check issues page.
- Inspiration from react-router-navigation-prompt
- Gist: https://gist.github.com/rmorse/426ffcc579922a82749934826fa9f743
Give a ⭐️ if this project helped you!
Copyright © 2023 Shyam Gupta (shyamm@outlook.com)
This project is MIT licensed.
- Website: sshyam-gupta.space
- Twitter: @shyamm06
- GitHub: @sshyam-gupta
- LinkedIn: @shyam-gupta-66463a62