🛡️ Middleware Pattern
Clean, composable guards that intercept navigation attempts before they reach your screens.
Route Guards provide middleware-style navigation protection for your applications. Think of them as security checkpoints that can allow, redirect, or block navigation based on your custom logic.
🛡️ Middleware Pattern
Clean, composable guards that intercept navigation attempts before they reach your screens.
🔧 Framework Agnostic
Core guard logic works with any routing system. Framework-specific integrations provide seamless developer experience.
⚡ Composable Logic
Combine simple guards into complex protection schemes with logical operators: AND, OR, XOR.
🎯 Precise Control
Fine-grained control over which routes are protected, with inclusion/exclusion patterns and conditional logic.
Every guard implements a simple middleware pattern:
class AuthGuard extends RouteGuard { @override FutureOr<void> onNavigation( NavigationResolver resolver, Object context, Object state, ) async { if (await isAuthenticated()) { resolver.next(); // ✅ Allow navigation } else { resolver.redirect('/login'); // 🔀 Redirect to login } }}
Guards receive a resolver that controls the navigation flow:
resolver.next()
- Allow navigation to continueresolver.redirect('/path')
- Redirect to a different routeresolver.block()
- Block navigation entirelyFramework-agnostic foundation providing:
RouteGuard
classNavigationResolver
patternSpecialized integrations for popular frameworks:
Combine guards to create sophisticated protection:
// All guards must pass (AND logic)final adminGuard = Guards.all([ AuthGuard(), RoleGuard(['admin']), PermissionGuard(['manage_users']),]);
// Any guard can pass (OR logic)final accessGuard = Guards.anyOf([ SubscriptionGuard(), StaffAccessGuard(), BetaTesterGuard(),]);
// Exactly one guard must pass (XOR logic)final exclusiveGuard = Guards.oneOf([ DevelopmentModeGuard(), ProductionAccessGuard(),]);
Authentication
Protect authenticated routes, handle login flows, manage session validation.
Authorization
Role-based access control, permission systems, organizational hierarchies.
Business Logic
Subscription gates, feature flags, trial limitations, geographic restrictions.
Security
Rate limiting, device verification, suspicious activity detection, compliance checks.
Multi-Tenant
Tenant isolation, cross-tenant security, workspace-specific access control.
A/B Testing
Experiment-based routing, feature rollouts, user segmentation.
Here’s how it looks with Go Router integration:
// Type-safe route with guards@TypedGoRoute<AdminRoute>(path: '/admin')class AdminRoute extends GoRouteData with GuardedRoute { @override RouteGuard get guards => Guards.all([ AuthGuard(), RoleGuard(['admin']), ]);
@override Widget build(context, state) => AdminScreen();}
// Traditional route with guardsGoRoute( path: '/admin', builder: (context, state) => AdminScreen(), redirect: RouteGuardUtils.createGuardRedirect( Guards.all([AuthGuard(), RoleGuard(['admin'])]), ),)
Add route guards to your project
Create your first guard in 5 minutes
Framework-agnostic foundation
Flutter Go Router integration
Route Guards - Secure navigation made simple