<Prompt /> component from react-router-dom misbehaves on cancelling navigation
See original GitHub issueI’ve recently migrated from version 3 to 4.1.2 in the hope that the following bug caused by the setRouteLeaveHook won’t be present in the <Prompt /> component from react-router-dom.
So, as per the use case of Prompt component, when the user standing in the form refreshes the page, edit some fields and clicks back button, the confirmation alert pops up and when the user cancels the navigation, it stays on the page but the url gets changed and does not remain the same as of the current form page.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:80
- Comments:62 (14 by maintainers)
Top Results From Across the Web
<Prompt /> component from react-router-dom misbehaves on ...
The issue is that the prompt is allowing the URL to change even after clicking on cancel navigation. This happens only after you...
Read more >Prevent Navigation with the React Router Prompt Component ...
In this lesson we'll show how to setup the Prompt component from React Router. ... return `true` from the message as a function...
Read more >React-router Prompt: How do I actually override the cancel ...
I looked into using react-router Prompt component and I have it ... the browser confirmation dialog and not navigate away from the page....
Read more >Prevent Navigation with the React Router Prompt Component
In this lesson we'll show how to setup the Prompt component from React Router. We'll prompt with a static message, as well as...
Read more >Error When Back Button Is Clicked When Using React Router ...
Ask questions<Prompt /> component from reactrouterdom misbehaves on cancelling navigation. I've recently migrated from version 3 to 4.1.2 in the hope that.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’m experiencing the exact same thing using
BrowserRouter. If the user clicks a link or does an operation that pushes a route to history everything works as expected. If however the user clicks the browser back button I get a prompt as expected but the URL in the address bar has changed to the previous path.If I then click cancel on the prompt indicating I do not wish to leave, one of two things will happen.
In both cases my current component is still shown and my components lifecycle hooks including
componentWillReceivePropsare called which messes up the state of my component.I experienced the same issue.
When I come from an in app route, the behaviour of Prompt is working as expected, but when I access the page directly with the url of the view containing the Prompt component and I trigger it, the browser url remains modified even if I click on cancel.
I made a repo to reproduce the issue : https://github.com/Edistra/react-router-dom-prompt-issue
I also made a gif of the issue :