restoreRouteInformation method

  1. @override
RouteInformation? restoreRouteInformation(
  1. RoutePath path
)
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(RoutePath path) {
  if (path.isUnknown) {
    return RouteInformation(location: '/404');
  }
  if (path.isHomePage) {
    return RouteInformation(location: '/');
  }
  if (path.hasParameter) {
    return RouteInformation(location: '/${path.routeName}/${path.parameter}');
  }
  if (path.hasRouteName) {
    return RouteInformation(location: '/${path.routeName}');
  }
  return null;
}