beforeLeave method
Called when a url changes, before the url is updated
Use vRedirector
if you want to redirect or stop the navigation.
DO NOT use VRouter methods to redirect.
vRedirector
also has information about the route you leave and the route you go to
saveHistoryState
can be used to save a history state before leaving
This history state will be restored if the user uses the back button
You will find the saved history state in the VRouteElementData
using
VRouter.of(context).historyState
Note that you should consider the navigation cycle to
handle this precisely, see https://vrouter.dev/guide/Advanced/Navigation%20Control/The%20Navigation%20Cycle
Also see:
- VRouteElement.beforeLeave for route level beforeLeave
- VWidgetGuard.beforeLeave for widget level beforeLeave
- VRedirector to known how to redirect and have access to route information
Implementation
@override
Future<void> beforeLeave(
VRedirector vRedirector,
void Function(Map<String, String> state) saveHistoryState,
) =>
voidBeforeLeave(vRedirector, saveHistoryState);