buildRoute method
VRoute?
buildRoute(
- VPathRequestData vPathRequestData, {
- required VPathMatch parentVPathMatch,
- required bool parentCanPop,
override
What this buildRoute does is look if any path or alias can give a valid VRoute considering this and the stackedRoutes
For more about buildRoute, see VRouteElement.buildRoute
Implementation
@override
VRoute? buildRoute(
VPathRequestData vPathRequestData, {
required VPathMatch parentVPathMatch,
required bool parentCanPop,
}) {
// This will hold the GetPathMatchResult for the path so that we compute it only once
late final VPathMatch pathMatch;
// This will hold every GetPathMatchResult for the aliases so that we compute them only once
List<VPathMatch> aliasesMatch = [];
// Try to find valid VRoute from stackedRoutes
// Check for the path
pathMatch = getPathMatch(
entirePath: vPathRequestData.path,
selfPath: path,
selfPathRegExp: pathRegExp,
selfPathParametersKeys: pathParametersKeys,
parentVPathMatch: parentVPathMatch,
);
final VRoute? stackedRouteVRoute = getVRouteFromRoutes(
vPathRequestData,
routes: stackedRoutes,
vPathMatch: pathMatch,
parentCanPop: parentCanPop,
);
if (stackedRouteVRoute != null) {
return VRoute(
vRouteElementNode: VRouteElementNode(
this,
localPath: pathMatch.localPath,
stackedVRouteElementNode: stackedRouteVRoute.vRouteElementNode,
),
pages: stackedRouteVRoute.pages,
pathParameters: stackedRouteVRoute.pathParameters,
vRouteElements:
<VRouteElement>[this] + stackedRouteVRoute.vRouteElements,
names: stackedRouteVRoute.names,
);
}
// Check for the aliases
for (var i = 0; i < aliases.length; i++) {
aliasesMatch.add(
getPathMatch(
entirePath: vPathRequestData.path,
selfPath: aliases[i],
selfPathRegExp: aliasesRegExp[i],
selfPathParametersKeys: aliasesPathParametersKeys[i],
parentVPathMatch: parentVPathMatch,
),
);
final VRoute? stackedRouteVRoute = getVRouteFromRoutes(
vPathRequestData,
routes: stackedRoutes,
vPathMatch: aliasesMatch[i],
parentCanPop: parentCanPop,
);
if (stackedRouteVRoute != null) {
return VRoute(
vRouteElementNode: VRouteElementNode(
this,
localPath: pathMatch.localPath,
stackedVRouteElementNode: stackedRouteVRoute.vRouteElementNode,
),
pages: stackedRouteVRoute.pages,
pathParameters: stackedRouteVRoute.pathParameters,
vRouteElements:
<VRouteElement>[this] + stackedRouteVRoute.vRouteElements,
names: stackedRouteVRoute.names,
);
}
}
// Else, if no subroute is valid
// // check if this is an exact match with path
// final vRoute = getVRouteFromSelf(
// vPathRequestData,
// vPathMatch: pathMatch,
// );
// if (vRoute != null) {
// return vRoute;
// }
//
// // Check exact match for the aliases
// for (var i = 0; i < aliases.length; i++) {
// final vRoute = getVRouteFromSelf(
// vPathRequestData,
// vPathMatch: aliasesMatch[i],
// );
// if (vRoute != null) {
// return vRoute;
// }
// }
// Else return null
return null;
}