Currently, I want to show a message to the user before the user navigates away from the page with unsaved changes. I looked into using react-router Prompt component and I have it setup like this:
import { Prompt } from 'react-router-dom';
function MyForm() {
const [isFormIncomplete, setIsFormIncomplete] = useState(true);
return (
<div>
<form>{/*form code*/}</form>
<Prompt
when={isFormIncomplete}
message="Are you sure you want to leave?" />
</div>
)
}
Currently, it showing the confirmation dialog just fine but I'm confused on how to override the cancel button. Right now, on cancel, it still navigates away from the page (same with ok) but on cancel, I just want to dismiss the browser confirmation dialog and not navigate away from the page. How do I do that? I don't see anything in the docs for overriding cancel behavior of the browser dialog?