go_router_guards 2.0.0+1 copy "go_router_guards: ^2.0.0+1" to clipboard
go_router_guards: ^2.0.0+1 copied to clipboard

A flexible and extensible guard system for Go Router that allows you to chain multiple guards together for route protection.

go_router_guards #

A flexible and powerful guard system for Go Router with middleware-style navigation control, enabling elegant route protection with expressive guard composition.

ci coverage pub package style: very good analysis License: MIT

Quick Start #

Install:

dependencies:
  go_router_guards: ^2.0.0+1

Create a guard:

class AuthGuard extends RouteGuard {
  @override
  void onNavigation(
    NavigationResolver resolver,
    BuildContext context,
    GoRouterState state,
  ) async {
    final isAuthenticated = await checkAuth();
    if (isAuthenticated) {
      resolver.next();
    } else {
      resolver.redirect('/login');
    }
  }
}

Use with type-safe routes:

@TypedGoRoute<AdminRoute>(path: '/admin')
class AdminRoute extends GoRouteData with GuardedRoute {
  @override
  RouteGuard get guard => [
    AuthGuard(),
    RoleGuard(['admin']),
  ].all();

  @override
  Widget build(BuildContext context, GoRouterState state) {
    return const AdminScreen();
  }
}

Or with traditional GoRouter:

GoRoute(
  path: '/admin',
  redirect: [AuthGuard(), RoleGuard(['admin'])].redirectAll(),
  builder: (context, state) => const AdminScreen(),
)

Documentation #

📚 Full documentation available at https://guards.aquiles.dev

Migrating from v1.x #

See the Migration Guide for detailed instructions on upgrading from v1.x to v2.x.

Quick summary of breaking changes:

// Before (v1.x)
class MyGuard implements RouteGuard {
  @override
  FutureOr<String?> redirect(BuildContext context, GoRouterState state) {
    if (condition) return '/redirect';
    return null;
  }
}

// After (v2.x)
class MyGuard extends RouteGuard {
  @override
  void onNavigation(
    NavigationResolver resolver,
    BuildContext context,
    GoRouterState state,
  ) {
    if (condition) {
      resolver.redirect('/redirect');
    } else {
      resolver.next();
    }
  }
}

Contributing #

See CONTRIBUTING.md for details.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

4
likes
150
points
2
downloads

Documentation

API reference

Publisher

verified publisheraquiles.dev

Weekly Downloads

A flexible and extensible guard system for Go Router that allows you to chain multiple guards together for route protection.

Repository (GitHub)
View/report issues
Contributing

License

MIT (license)

Dependencies

flutter, go_router, meta

More

Packages that depend on go_router_guards