import 'package:flutter/cupertino.dart' hide RouterConfig; import 'package:go_router/go_router.dart'; import 'config/route_paths.dart'; import 'config/router_config.dart'; import 'modules/home_routes.dart'; List routeConfigs = [...homeRoutes]; //for循环遍历 List routes = routeConfigs.map((item) { return GoRoute( path: item.path, builder: (context,state){ return item.child(state); } ); }).toList(); GlobalKey navigatorKey = GlobalKey(); //变量命名 GoRouter goRouter = GoRouter( navigatorKey: navigatorKey, initialLocation: RoutePaths.home, routes: routes, );