Giter Site home page Giter Site logo

Comments (8)

mattermoran avatar mattermoran commented on June 15, 2024 1

nope. I had to add a guard on specific routes rather than global one

from auto_route_library.

mattermoran avatar mattermoran commented on June 15, 2024 1

Oh as I was typing out my solution I realized the difference between my global guard that's not working and local. In my local one I'm using router.replaceAll([RouteToShow()]) instead of resolver.redirect(RouteToShow()).
Just tried to use router.replaceAll in my global and it seems to be working fine.

The only issue is having to also check for root but honestly that's not a big deal.

from auto_route_library.

Milad-Akarie avatar Milad-Akarie commented on June 15, 2024 1

router.current is not the route being intercepted by guard, resolver.route is.

from auto_route_library.

mattermoran avatar mattermoran commented on June 15, 2024 1

No the docs seems to be ok. Just tested with resolver.route.name and it works like charm.
my bad :)

and thanks!

from auto_route_library.

lcardosol avatar lcardosol commented on June 15, 2024

Have you solved this? I got the same problem, for me it causes blank screen and an exception on the console, here is my issue #1818

from auto_route_library.

lcardosol avatar lcardosol commented on June 15, 2024

nope. I had to add a guard on specific routes rather than global one

Would you mind sharing your temporary solution? I did try to assign them manually by separating the guard in its own class like tis:

class AuthGuard extends AutoRouteGuard {
  AuthGuard({
    required this.authState,
  }) : super();

  final AuthStateNotifer authState;

  @override
  void onNavigation(NavigationResolver resolver, StackRouter router) {
    final isLoginRoute = router.current.name == SignInRoute.name;
    final isSignUpRoute = router.current.name == SignUpRoute.name;
    final isAuthPage = isLoginRoute || isSignUpRoute;

    if (authState.isLogged && isAuthPage) {
      resolver.redirect(const HomeRoute());
    } else if (authState.isLogged && !isAuthPage) {
      resolver.next(true);
    } else if (!authState.isLogged && isAuthPage) {
      resolver.next(true);
    } else if (router.current.name == 'Root') {
      resolver.next(true);
    } else {
      resolver.redirect(const SignInRoute());
    }
  }
}

Like this it works, but it concerns me that I have to check on that specific route Root otherwise it causes the onNavigation to be triggered infinitly.

from auto_route_library.

mattermoran avatar mattermoran commented on June 15, 2024

well it's official now, I can't read it seems

from auto_route_library.

Milad-Akarie avatar Milad-Akarie commented on June 15, 2024

Or maybe whoever wrote the docs made a mistake...

from auto_route_library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.