useBeforeLeave
Edit this pageuseBeforeLeave
takes a function that will be called prior to leaving a route.
The function will be called with:
- from (Location): current location (before change).
- to (string | number}: path passed to
navigate.
- options (NavigateOptions}: options passed to
navigate.
- preventDefault (void function): call to block the route change.
- defaultPrevented (readonly boolean):
true
if any previously called leave handlers calledpreventDefault()
. - retry (void function, force?: boolean ): call to retry the same navigation.
Pass
true
to skip running the leave handlers again (ie. force navigate without confirming).
Example usage: