ParameterizedGuard<P> class abstract

A route guard that accepts configuration parameters.

Use this when you need to configure guard behavior per-route.

Example:

class RoleGuard extends ParameterizedGuard<List<String>> {
  RoleGuard(super.params);

  @override
  Future<GuardResult> onBefore(RouteContext context) async {
    final user = await Auth.user();
    if (!params.any((role) => user.hasRole(role))) {
      return redirect('/unauthorized');
    }
    return next();
  }
}

// Usage:
router.route(
  AdminPage.path,
  (_) => AdminPage(),
  routeGuards: [RoleGuard(['admin', 'moderator'])],
);
Inheritance

Constructors

ParameterizedGuard(P params)

Properties

context → BuildContext?
Convenience getter for the build context.
no setterinherited
data → dynamic
Convenience getter for the route data.
no setterinherited
hashCode → int
The hash code for this object.
no setterinherited
hasModifiedData → bool
Whether setData was called during this guard's execution.
no setterinherited
modifiedData → dynamic
Get modified data if setData was called.
no setterinherited
pageRequest ↔ PageRequest?
getter/setter pairinherited
params → P
The parameters passed to this guard.
final
queryParameters → Map<String, String>
Convenience getter for query parameters.
no setterinherited
redirectConfig → RedirectConfig?
Get the redirect configuration if a redirect was requested.
no setterinherited
routeContext → RouteContext?
The current route context.
no setterinherited
routeName → String?
Convenience getter for the route name.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

abort() → GuardResult
Abort navigation without redirecting.
inherited
next() → GuardResult
Continue to the next guard or to the route.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onAfter(RouteContext context) → Future<void>
Called after successful navigation to the route.
inherited
onBefore(RouteContext context) → Future<GuardResult>
Called before navigation to the route.
inherited
onRequest(PageRequest pageRequest) → Future<PageRequest?>
Legacy method override for backward compatibility. Delegates to the new onBefore lifecycle method.
inherited
redirect(Object path, {dynamic data, Map<String, dynamic>? queryParameters, NavigationType navigationType = NavigationType.pushReplace, dynamic result, bool removeUntilPredicate(Route route)?, TransitionType? transitionType, dynamic onPop(dynamic value)?}) → GuardResult
Redirect to a different route.
inherited
setData(dynamic data) → void
Modify the data passed to subsequent guards and the route.
inherited
setRouteContext(RouteContext context) → void
Set the route context. Called by the router.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited