RouteGuard class abstract
Abstract base class for route guards.
Guards intercept navigation and can allow, redirect, or block it. Guards run in priority order (lower number = earlier execution).
Example:
class AuthGuard extends RouteGuard {
final bool Function() isAuthenticated;
AuthGuard({required this.isAuthenticated});
@override
String get name => 'AuthGuard';
@override
Future<GuardResult> check(RouteContext context) async {
if (isAuthenticated()) {
return const GuardResult.allow();
}
return GuardResult.redirect('/login', returnTo: context.targetPath);
}
}
- Implementers
Constructors
- RouteGuard()
-
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- name → String
-
Human-readable name for this guard (used in error messages and logging)
no setter
- priority → int
-
Priority for guard execution order.
Lower numbers execute first. Default is 100.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
check(
RouteContext context) → Future< GuardResult> - Check whether navigation should proceed.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited