用途:为 Flutter 项目提供一套 go_router 路由组织约定,覆盖路径常量、路由定义、底部导航、路径参数与页面跳转。
主要能力与约定:路径字符串统一放在 lib/core/routing/route_paths.dart 的 RoutePaths 抽象类中,代码中不直接写原始字符串;路由定义集中在 lib/core/routing/router.dart,GoRouter 实例以全局 router 变量暴露,由 main.dart 的 MaterialApp.router 消费;路由 builder 只构建 Root 组件,DI、事件与状态订阅由 Root 负责。顶层路径用 /<Name> 形式,嵌套路径带上级前缀(如 /Home/Ingredient/:recipeId),路径参数用 :name 标记。
用法要点:路径参数从 state.pathParameters 取字符串,在 builder 内做类型转换后传给 Root,例如 int.parse(state.pathParameters['recipeId']!)。跳转时 context.go 替换栈(如登录后进首页),context.push 压栈(如进入详情页)。底部导航用 StatefulShellRoute.indexedStack,各 Tab 为 StatefulShellBranch,通过 navigationShell.goBranch(index, initialLocation: index == navigationShell.currentIndex) 切换,重复点击可回到该 Tab 根页。简单页面可只接收回调(如 onTapSignIn),由路由注入,使 Screen 不直接依赖 go_router。
适用场景:需要多 Tab 各自保留导航栈、需要集中管理路径与参数的 Flutter 应用。
限制与反模式:不要在 ViewModel 中调用 context.go;不要在 Screen 中直接 import go_router;不要混用 Navigator.push(MaterialPageRoute);必填参数应强制解包以暴露路由定义错误。资料未提供安装命令、版本要求与平台信息。