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,
              extra: state.extra,
              queryParametersAll: state.queryParametersAll,
              queryParams: state.queryParams,
            ),
          ),
          name: e.name,
          routes: e.routes != null && e.routes!.isNotEmpty
              ? generateRoutes(
                  e.routes!,
                  parentNavigatorKey,
                )
              : <RouteBase>[],
          redirect: (context, state) async {
            if (e.shouldRedirect != null && e.redirectRoute != null) {
              if (e.shouldRedirect!()) {
                Uri uri = Uri.base;
                if (!e.externalRoute) {
                  return " ${e.redirectRoute}?redirecturl=${uri.fragment}";
                } else {
                  if (e.redirectRoute != null) {
                    UpUrlService().openUrl(
                        "${e.redirectRoute}?redirecturl=${Uri.parse('${uri.origin}/#${uri.fragment}')}",
                        webOnlyWindowName: "_self");
                    return null;
                  }
                }
              } else {
                return null;
              }
            } else {
              return null;
            }
            return null;
          },
        ),
      )
      .toList();

  return routes;
}