auto_route_library icon indicating copy to clipboard operation
auto_route_library copied to clipboard

[Web] Navigate back to page with required argument

Open peer-f opened this issue 1 year ago • 7 comments

I have a page structure where I use arguments to provide data between screens inside of my authentication flow. The screens are reused from other locations inside of the app so they need to be able to accept arguments. The routes are not nested.

simplified page structure:

- welcome
- sign in (argument)
- sign up (argument)
- forgot password (argument)
...

When I navigate from welcome to sign in and from there to forgot password and then press the back button the browser seems to loose the argument that is required by sign in.

After pressing the back button on forgot password I get routed back to welcome with this error message:

Error: 
SignInRouteArgs can not be null because the corresponding page has a required parameter

dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 294:49  throw_
packages/auto_route/src/route/route_data.dart 99:9                            argsAs
packages/auth/src/navigator/auth_router.gm.dart 57:29                         <fn>
packages/auto_route/src/router/controller/root_stack_router.dart 169:19       [_pageBuilder]
packages/auto_route/src/router/controller/routing_controller.dart 1547:29     [_addEntry]
packages/auto_route/src/router/controller/routing_controller.dart 1522:29     _pushAllGuarded
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50            <fn>
dart-sdk/lib/async/zone.dart 1661:54                                          runUnary
dart-sdk/lib/async/future_impl.dart 156:18                                    handleValue
dart-sdk/lib/async/future_impl.dart 840:44                                    handleValueCallback
dart-sdk/lib/async/future_impl.dart 869:13                                    _propagateToListeners
dart-sdk/lib/async/future_impl.dart 458:9                                     callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                              _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                               _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:15           <fn>

I would prefer not to use query parameters because there might be data that I don't want to expose in the url (our onboarding is really long and complex).

Thanks a lot for your help!

peer-f avatar Jan 19 '24 16:01 peer-f

@Milad-Akarie Could this be an issue related to the way the browser history is saved? I had the same issue when using go_router where I had to provide encoding and decoding methods for data provided as extra argument.

peer-f avatar Jan 22 '24 08:01 peer-f

I am facing the same issue with declarative router..

adar2378 avatar Feb 12 '24 09:02 adar2378

im facing this issue too, i got this issue when i navigate back from previous screen that require an argument.

Vladeouz avatar Feb 28 '24 08:02 Vladeouz

i'm running into the same issue...would be awesome to get that fixed asap, thanks!

MikaHen avatar Feb 29 '24 11:02 MikaHen

@Milad-Akarie any updates on this issue? This issue causes lots of problems in our production web app.

peer-f avatar Apr 23 '24 12:04 peer-f

Hey @peer-f I suggest you adjust your design so you don't pass objects when working with web, even if somehow I support this usecase you still have to handle page refresh and deeplinking.

Milad-Akarie avatar Apr 23 '24 12:04 Milad-Akarie

@Milad-Akarie thanks for the quick response!

So there is no way to store this data internally like go_router does?

Our application shares most of its business logic between mobile and web only the UI differs so I'd have to change this for the whole application.

I think the way arguments are handled in auto_route is really great which is why we use it most of the time.

Could this be solved if there was a way to provide serialization/deserialization logic for each query parameter? This way both page refresh and deeplinking could be achieved.

peer-f avatar Apr 23 '24 13:04 peer-f