Warning to not resolve more than once
The isResolved guard clause prevents redirect to be called more than once.
/// Redirect to a different path
void redirect(String path) {
if (isResolved) return;
_completer.complete(GuardResult.redirect(path));
}
It is still possible to create a RouteGuard with mulitple calls to .redirect which will not work as expected.
This might be a normal pattern for this kind of implementation, but people unknown with the resolver pattern micht benefit from a warning in the documentation.
Example Guard
class TestGuard extends RouteGuard {
@override
FutureOr<void> onNavigation(NavigationResolver resolver, BuildContext context, GoRouterState state) async {
resolver.next();
resolver.redirect('/');
// Do something here
await Future.delayed(const Duration(seconds: 2));
resolver.redirect('login');
}
}
Btw. I am not arguing that is a good idea to call it twice or thrice.
Warning to not resolve more than once
The
isResolvedguard clause prevents redirect to be called more than once.It is still possible to create a RouteGuard with mulitple calls to
.redirectwhich will not work as expected.This might be a normal pattern for this kind of implementation, but people unknown with the resolver pattern micht benefit from a warning in the documentation.
Example Guard
Btw. I am not arguing that is a good idea to call it twice or thrice.