BloomRouteGuard class abstract
Abstract contract for route navigation guards.
Guards intercept route transitions before a route match is rendered. If any
guard attached to a BloomRoute returns a GuardResult where GuardResult.isAllowed
is false, the navigation sequence is halted and the router redirects to
GuardResult.redirectPath if one was specified.
Guards can be synchronous or asynchronous.
class AdminGuard extends BloomRouteGuard {
final Future<bool> Function() checkAdmin;
const AdminGuard(this.checkAdmin);
@override
Future<GuardResult> canActivate(String location, Map<String, String> params) async {
final isAdmin = await checkAdmin();
return isAdmin ? GuardResult.allow() : GuardResult.redirect('/unauthorized');
}
}
Constructors
- BloomRouteGuard()
-
Base const constructor for route guards.
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
canActivate(
String location, Map< String, String> params) → FutureOr<GuardResult> -
Evaluates whether navigation to
locationwith extracted routeparamsis allowed. -
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