import 'package:go_router/go_router.dart'; import 'package:maibu_satabot_v2/core/router/route_paths.dart'; import 'package:maibu_satabot_v2/features/ai/presentation/routes/ai_routes.dart'; import 'package:maibu_satabot_v2/features/auth/presentation/routes/auth_routes.dart'; import 'package:maibu_satabot_v2/features/home/presentation/routes/home_routes.dart'; import 'package:maibu_satabot_v2/features/my/presentation/routes/my_routes.dart'; import '../../features/auth/presentation/bloc/auth_cubit.dart'; import '../../features/auth/presentation/bloc/auth_state.dart'; import '../../features/main_container/presentation/main_wrapper.dart'; import 'go_router_refresh_stream.dart'; GoRouter createRouter(AuthCubit authCubit) { return GoRouter( initialLocation: RoutePaths.login, refreshListenable: GoRouterRefreshStream(authCubit.stream), redirect: (context, state) { final loggedIn = authCubit.state is AuthAuthenticated; final loggingIn = state.matchedLocation == RoutePaths.login; if (!loggedIn && !loggingIn) { return RoutePaths.login; } if (loggedIn && loggingIn) { return RoutePaths.home; } return null; }, routes: [ // 1. 外部路由(无底部导航栏) ...AuthRoutes.routes, ...HomeRoutes.routes, ...AiRoutes.routes, ...MyRoutes.routes, // 2. 内部路由(带底部导航栏的容器) StatefulShellRoute.indexedStack( builder: (context, state, navigationShell) { // 返回我们定义的 MainWrapper return MainWrapper(navigationShell: navigationShell); }, branches: [ // 拿一级页面 HomeRoutes.branch, AiRoutes.branch, MyRoutes.branch, ], ), ], ); }