buildRoute method

VRoute? buildRoute(
  1. VPathRequestData vPathRequestData, {
  2. required VPathMatch parentVPathMatch,
  3. required bool parentCanPop,
})
inherited

buildRoute must return VRoute if it constitute (which its subroutes or not) a valid route given the input parameters VRoute should describe this valid route

vPathRequestData contains all the information about the original request coming from VRouter It should not be changed and should be given as-is to its subroutes

parentRemainingPath is the part on which to base any local path WARNING: parentRemainingPath is null if the parent did not match the path in which case only absolute path should be tested.

parentPathParameters are the path parameters of every VRouteElement above this one in the route

buildRoute basically just checks for a match in stackedRoutes and if any adds this VRouteElement to the VRoute

For more info on buildRoute, see VRouteElement.buildRoute

Implementation

VRoute? buildRoute(
  VPathRequestData vPathRequestData, {
  required VPathMatch parentVPathMatch,
  required bool parentCanPop,
}) {
  VRoute? childVRoute;
  for (var vRouteElement in _subroutes) {
    childVRoute = vRouteElement.buildRoute(
      vPathRequestData,
      parentVPathMatch: parentVPathMatch,
      parentCanPop: parentCanPop,
    );
    if (childVRoute != null) {
      return VRoute(
        vRouteElementNode: VRouteElementNode(
          this,
          localPath: null,
          stackedVRouteElementNode: childVRoute.vRouteElementNode,
        ),
        pages: childVRoute.pages,
        pathParameters: childVRoute.pathParameters,
        vRouteElements: <VRouteElement>[this] + childVRoute.vRouteElements,
        names: parentVPathMatch.names,
      );
    }
  }

  // If none where found, test if this [VRouteElement] can create a [VRoute]
  final validParentVPathMatch = (parentVPathMatch is ValidVPathMatch) &&
      parentVPathMatch.remainingPath.isEmpty;
  if (!mustHaveSubRoutes && validParentVPathMatch) {
    return VRoute(
      vRouteElementNode: VRouteElementNode(
        this,
        localPath: null,
      ),
      pages: [],
      pathParameters: (parentVPathMatch as ValidVPathMatch).pathParameters,
      vRouteElements: <VRouteElement>[this],
      names: parentVPathMatch.names,
    );
  }

  return null;
}