React router v6 doesn't support <Prompt /> or usePrompt

Viewed 6353

Migrating a codebase to react-router v6 specifically v6.2.1 and running into some issues when trying to use <Prompt /> component or usePrompt, turns out they are not available in this version of react-router. Or am I wrong? If anyone have run in to the same issue or if you know a way around this issue, your help would be appreciated.

3 Answers

As it says in the documentation:

<Prompt> from v5 (along with usePrompt and useBlocker from the v6 betas) are not included in the current released version of v6. We decided we'd rather ship with what we have than take even more time to nail down a feature that isn't fully baked. We will absolutely be working on adding this back in to v6 at some point in the near future, but not for our first stable release of 6.x.

So you have two options:

  1. Create your own component and handle the logic there.
  2. Downgrade react-router-dom to v5.

Source: https://reactrouter.com/docs/en/v6/upgrading/v5#prompt-is-not-currently-supported

Prompt is currently not supported in react-router-dom 6

Prompt not supported at the moment

Resort to the following:

  1. Writing your own prompt component
  2. installing react-router-dom 5 and using prompt.
Related