Prevent Transitions

Sometimes you may want to aler the user that if they navigate away from the page they are in, they may lose something, etc. React router actually gives us a component for this out of the box to render a little browser alert letting the user know and if they press cancel, cancelling the request to navigate to another route and if they press ok, moving them away.

It would look something like this:


You can see a full example here:


Prevent Transitions - CodeSandbox

Prevent Transitions - CodeSandbox

Copyright 2023 © Borja Leiva

Made within London