I'm developing with react-router-dom. Now, I'm creating a page where users can enter information in a form. What I want to do is prevent the user from losing the information they enter if they accidentally return to the previous page.
I first found a way to stop the browser back in the article below. It seems that the moment you return to the previous page, you immediately return to the original page, effectively preventing you from returning to the previous page.
React.useEffect (() => {
return () => {
props.history.goForward ();
}
}, []);
React Router Dom v4 handle browser back button
However, in this case, the previous page will be returned once, so all the current page information (state) will be reset. Is there a solution to prevent the state from resetting? Or is there a smarter way to solve this?
Below, I have prepared an image for explanation.