Giter Club home page Giter Club logo

Comments (8)

csells avatar csells commented on August 15, 2024

you need to set a refreshListenable as per the README

from go_router.

doughywilson avatar doughywilson commented on August 15, 2024

Is that required? I can't seem to find where in the documentation is says it's required, and it shows and example of using the redirect without refreshListenable. Even so, I tried adding a refreshListenable and still get the same behavior.

from go_router.

csells avatar csells commented on August 15, 2024

You're right -- you don't have to use a refreshListenable if you're manually navigating.

You've got a redirect loop:

Exception: Redirect loop detected: / => /login => /login

You can see it if you show the exception in your error page:

errorPageBuilder: (context, state) => MaterialPage<void>(
  key: state.pageKey,
  child:  Scaffold(
    body: Text(state.error.toString()),
  ),
),

Redirection is called repeatedly until a null is returned. This allows for multiple route redirections, etc. before landing at the desired page, which in turn allows for routes in an app to build up over time, keeping the old routes but redirecting them to the new ones.

from go_router.

doughywilson avatar doughywilson commented on August 15, 2024

Oh I see, thanks! I like that. This would be super helpful to point out directly in the documentation. I didn't realize that the redirect function would run until it returns null.

from go_router.

csells avatar csells commented on August 15, 2024

Ha. Way ahead of you. The README in the repo is already updated and it'll be updated on pub.dev on the next release. The next release will also include exception info in the debug output in the case that you've got route debugging turned on. Your questions and feedback have been super helpful.

How's your use case? Are things working they way you want?

from go_router.

doughywilson avatar doughywilson commented on August 15, 2024

Sweet!

I'm now trying to figure out how to initialize my app correctly. I'm having some complications when it comes to when/how to load a stored api key BEFORE the go_router attempts to run the redirect function and begin routing. It's tricky because the loading of the api key is asynchronous.

I'm also having this really annoying issue of not being able to hot reload my app. Whenever I make changes, the screen goes white and refuses to come back, even if I manually refresh the browser. Not ready to blame that on go_router though.

It would be cool if go_router had some kind of built in paradigm for initializing auth state to avoid these async/init headaches. Not sure if that's possible though.

from go_router.

csells avatar csells commented on August 15, 2024

You can do async init before even running your app, e.g.

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

Of course, you can bake auth init into how you route, too, and use it as input for redirection.

from go_router.

doughywilson avatar doughywilson commented on August 15, 2024

Yeah, tried that strategy but still having some hangups. Maybe I'm screwing something up though.

from go_router.

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.