Architecture
Overview
Section titled “Overview”go_router_guards implements a middleware pattern around Go Router’s redirects.
- Route code defines guard(s) via
GuardedRoute/GuardedShellRouteor traditionalredirect. - A
RouteGuardreceivesNavigationResolver,BuildContext, andGoRouterState. - The guard resolves by calling
next(),redirect(path), orblock().
Why a resolver pattern?
Section titled “Why a resolver pattern?”It makes asynchronous and branching flows straightforward and testable. Guards compose cleanly using guardAll, guardAnyOf, and guardOneOf.
Router vs route‑level
Section titled “Router vs route‑level”- Router‑level (via
ConditionalGuard) is great for cross‑cutting checks (e.g., auth). - Route‑level focuses on local authorization (e.g., role/permission).