beforeLeave property
Called when the route changes and the VRouteElement associated to this VWidgetGuard is in the previous route but not in the new one
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
Use newVRouteData
if you want information on the new route but be
careful, on the web newVRouteData is null when a user types a url manually
Use newVRouteData
if you want information on the new route but be
careful, on the web newVRouteData is null when a user types a url manually
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
VRouteElementData.of(context).historyState
WARNING: Since the history state is saved in VRouteElementData
, if you have
multiple VWidgetGuards associated to the same VRouteElement, only one
should use saveHistoryState
.
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:
- VRouter.beforeLeave for global level beforeLeave
- VRouteElement.beforeLeave for route level beforeLeave
- VRedirector to known how to redirect and have access to route information
Implementation
final Future<void> Function(
VRedirector? vRedirector,
void Function(Map<String, String> state) saveHistoryState,
) beforeLeave;