parseRouteInformation method

  1. @override
SynchronousFuture<GetNavConfig> parseRouteInformation(
  1. RouteInformation routeInformation
)
override

Converts the given route information into parsed data to pass to a RouterDelegate.

The method should return a future which completes when the parsing is complete. The parsing may be asynchronous if, e.g., the parser needs to communicate with the OEM thread to obtain additional data about the route.

Consider using a SynchronousFuture if the result can be computed synchronously, so that the Router does not need to wait for the next microtask to pass the data to the RouterDelegate.

One can implement parseRouteInformationWithDependencies instead if the parsing depends on other dependencies from the BuildContext.

Implementation

@override
SynchronousFuture<GetNavConfig> parseRouteInformation(
  RouteInformation routeInformation,
) {
  final uri = routeInformation.uri;
  var location = uri.toString();
  if (location == '/') {
    //check if there is a corresponding page
    //if not, relocate to initialRoute
    if (!Get.routeTree.routes.any((element) => element.name == '/')) {
      location = initialRoute;
    }
  } else if (location.isEmpty) {
    location = initialRoute;
  }

  Get.log('GetInformationParser: route location: $location');

  final matchResult = Get.routeTree.matchRoute(location);

  return SynchronousFuture(
    GetNavConfig(
      currentTreeBranch: matchResult.treeBranch,
      location: location,
      state: routeInformation.state,
    ),
  );
}