一键导入
add-guard
Create and apply route guards in Modugo to protect routes with conditional logic
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Create and apply route guards in Modugo to protect routes with conditional logic
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
| name | add-guard |
| description | Create and apply route guards in Modugo to protect routes with conditional logic |
Guards implement IGuard and decide whether navigation to a route should proceed or redirect.
final class AuthGuard implements IGuard {
@override
FutureOr<String?> canActivate(BuildContext context, GoRouterState state) {
final auth = Modugo.i.get<AuthService>();
if (auth.isAuthenticated) return null; // allow navigation
return '/login'; // redirect
}
}
null to allow navigationString) to redirectasync (Future<String?>)child(
'/dashboard',
builder: (_, _) => const DashboardPage(),
guards: [AuthGuard()],
)
Guards on module() propagate automatically to every route inside the module.
module(
'/admin',
AdminModule(),
guards: [AuthGuard(), AdminRoleGuard()],
)
Guards are evaluated in order. The first one that returns a non-null path stops the chain.
guards: [AuthGuard(), FeatureFlagGuard('admin-panel')]
final class SessionGuard implements IGuard {
@override
Future<String?> canActivate(BuildContext context, GoRouterState state) async {
final session = await Modugo.i.get<SessionService>().validate();
return session.isValid ? null : '/session-expired';
}
}
BuildContext and GoRouterState — access DI via Modugo.i.get<T>() or context.read<T>()canActivate are caught, logged, and rethrown — the navigation is blockedmodule() route applies to all ChildRoute descendants automaticallyCreate a new Modugo module with routes, binds, and imports
Create routes in Modugo using ChildRoute, ModuleRoute, ShellModuleRoute, StatefulShellModuleRoute, or AliasRoute
Register and access dependencies in Modugo modules using GetIt via the binds() method
Contexto completo do projeto Modugo — lib Flutter de roteamento modular e injeção de dependência sobre GoRouter + GetIt. Carregue esta skill sempre que for explorar, implementar, especificar ou revisar qualquer coisa no repositório.