reevaluate method

  1. @override
void reevaluate(
  1. AutoRedirectGuardBase guard,
  2. StackRouter router
)
override

Implementation

@override
void reevaluate(AutoRedirectGuardBase guard, StackRouter router) {
  final routes = router.stackData.map((e) => e.route).toList();
  final firstGuardedRouteIndex =
      routes.indexWhere((r) => r.guards.contains(guard));
  if (firstGuardedRouteIndex == -1) return;
  final routesToRemove =
      routes.sublist(firstGuardedRouteIndex, routes.length);
  for (final route in routesToRemove) {
    router._removeRoute(route, notify: false);
  }

  final routesToPush = <RouteMatch>[];
  for (final existingMatch in routes.sublist(
    firstGuardedRouteIndex,
    routes.length,
  )) {
    final routeToPush = router.matcher.matchByRoute(
      existingMatch.toPageRouteInfo(),
    );
    if (routeToPush != null) {
      routesToPush.add(routeToPush);
    }
  }
  router._pushAllGuarded(routesToPush);
}