restoreRouteInformation method

  1. @override
RouteInformation? restoreRouteInformation(
  1. RouteMatchList configuration
)
override

Restore the route information from the given configuration.

This may return null, in which case the browser history will not be updated and state restoration is disabled. See Router's documentation for details.

The parseRouteInformation method must produce an equivalent configuration when passed this method's return value.

Implementation

@override
RouteInformation? restoreRouteInformation(RouteMatchList configuration) {
  if (configuration.isEmpty) {
    return null;
  }
  String? location;
  if (GoRouter.optionURLReflectsImperativeAPIs &&
      (configuration.matches.last is ImperativeRouteMatch ||
          configuration.matches.last is ShellRouteMatch)) {
    RouteMatchBase route = configuration.matches.last;
    // Drill down to find the appropriate ImperativeRouteMatch.
    while (route is! ImperativeRouteMatch) {
      if (route is ShellRouteMatch && route.matches.isNotEmpty) {
        route = route.matches.last;
      } else {
        break;
      }
    }
    if (route case final ImperativeRouteMatch safeRoute) {
      location = safeRoute.matches.uri.toString();
    }
  }
  return RouteInformation(
    uri: Uri.parse(location ?? configuration.uri.toString()),
    state: _routeMatchListCodec.encode(configuration),
  );
}