Skip to content

docs: add warning to not call the resolver more than once #19

Description

@jlnrrg

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions