generateRoutes static method

List<RouteBase> generateRoutes(
  1. List<UpRoute> upRoutes,
  2. GlobalKey<NavigatorState>? parentNavigatorKey
)

Implementation

static List<RouteBase> generateRoutes(
    List<UpRoute> upRoutes, GlobalKey<NavigatorState>? parentNavigatorKey) {
  List<RouteBase> routes = upRoutes
      .map(
        (e) => GoRoute(
          // parentNavigatorKey: parentNavigatorKey,
          path: e.path,
          builder: (BuildContext context, GoRouterState state) =>
              e.pageBuilder(
            context,
            UpRouterState(
              params: state.params,
              queryParametersAll: state.queryParametersAll,
              queryParams: state.queryParams,
            ),
          ),
          name: e.name,
          routes: e.routes != null && e.routes!.isNotEmpty
              ? generateRoutes(
                  e.routes!,
                  parentNavigatorKey,
                )
              : <RouteBase>[],
          redirect: (context, state) {
            if (e.shouldRedirect != null && e.redirectRoute != null) {
              if (e.shouldRedirect!()) {
                return e.redirectRoute;
              } else {
                return null;
              }
            } else {
              return null;
            }
          },
        ),
      )
      .toList();

  return routes;
}