Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React: How to prompt for unsaved changes when navigating with react-router-component

Redux state holds flag for unsaved changes, and I want to prompt user when navigating (clicks a Link) if this flag is set. I'm using react-router-component. I didn't find how to do this in documentation.

like image 735
Tuomas Toivonen Avatar asked Jul 21 '16 10:07

Tuomas Toivonen


1 Answers

Anyone reaching this post in 2018 and using the react router 4+, I'd suggest reading this reacttraining example

TL;DR use the Prompt component at the top

<Prompt
    when={hasUnsavedChanges}
    message="There are unsaved changes, do you wish to discard them?"
/>

enter image description here

like image 127
Jay Wick Avatar answered Sep 27 '22 20:09

Jay Wick