canActivate method
Called by the router when a transition is requested from router states.
The client should return a future that completes with true
in order to
accept the transition, or completes with false
in order to reject it
(and prevent the routing from occurring).
You can use async
in order to simplify when returning synchronously:
class MyComponent implements CanActivate {
@override
Future<bool> canActivate(RouterState _, RouterState __) async {
// Maybe this page isn't ready yet for production, so always reject.
return false;
}
}
This lifecycle occurs after CanDeactivate.canDeactivate
.
Implementation
Future<bool> canActivate(RouterState? current, RouterState next) async {
// Provided as a default if someone extends or mixes-in this interface.
return true;
}