首页/ AI 技能 / @skilllib/skill-2117939930272417669
Skill站外收录 @skilllib/skill-2117939930272417669

go-router-navigation

实现类型安全的路由导航与状态管理,支持通过声明式方式定义嵌套路由、参数传递及重定向逻辑,结合代码生成确保编译时检查,适用于需要深度链接和权限跳转的多层级页面架构。

0.0 (0) 12 次安装 原作者 编程导航
收录于 2026-01-22
软件开发 AI 技能

Skills.MD

# GoRouter Navigation ## **Priority: P0 (CRITICAL)** Type-safe deep linking and routing system using `go_router` and `go_router_builder`. ## Structure ```text core/router/ ├── app_router.dart # Router configuration └── routes.dart # Typed route definitions (GoRouteData) ``` ## Implementation Guidelines - **Typed Routes**: Always use `GoRouteData` from `go_router_builder`. Never use raw path strings. - **Root Router**: One global `GoRouter` instance registered in DI. - **Sub-Routes**: Nest related routes using `TypedGoRoute` and children lists. - **Redirection**: Handle Auth (Login check) in the `redirect` property of the `GoRouter` config. - **Parameters**: Use `@TypedGoRoute` to define paths with `:id` parameters. - **Transitions**: Define standard transitions (Fade, Slide) in `buildPage`. - **Navigation**: Use `MyRoute().go(context)` or `MyRoute().push(context)`. ## Code ```dart // Route Definition @TypedGoRoute<HomeRoute>(path: '/') class HomeRoute extends GoRouteData { @override Widget build(context, state) => const HomePage(); } // Router Config final router = GoRouter( routes: $appRoutes, redirect: (context, state) { if (notAuthenticated) return '/login'; return null; }, ); ``` ## Related Topics layer-based-clean-architecture | auto-route-navigation | security

评论 0

还没有评论,来抢沙发。