csells / go_router

The purpose of the go_router for Flutter is to use declarative routes to reduce complexity, regardless of the platform you're targeting (mobile, web, desktop), handling deep linking from Android, iOS and the web while still allowing an easy-to-use developer experience.
https://gorouter.dev
442 stars 96 forks source link

Hot reload and refresh problem #200

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hi, In the example of "books" if I am located, for example, at "http://localhost:49325/#/authors" and I click on the refresh button of the browser, the page is changed to "http://localhost:49325/#/signin". Also if I do a "hot reload" being on any page, the page is changed to "http://localhost:49325/#/signin": This is a serious problem. Thanks for your help. Regards, Jose

csells commented 2 years ago

Flutter web does not have stateful hot reload, so when you make a change, it does a hot refresh instead. When that happens, if you haven't persisted the user's login state, e.g. via shared_preferences, then your user is not logged in and is redirected to the signin page. If you want to turn off redirection while debugging, you can do something like:

...
redirect: (state) {
  if (kDebugMode) return null;
  ...
}
..

Flutter web will use deep linking to keep you at the current page while you're doing hot refresh, so if you use this trick, you should stay on the same page as you make changes. Also, if you persist the user's credentials between sessions, either manually via something like shared_preferences or using Firebase Auth, which can automatically persist credentials between sessions depending on your app's settings, then that should work, too.