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
441 stars 96 forks source link

[question] how to implement restoreState() for deep linking? #177

Closed chunghha closed 2 years ago

chunghha commented 2 years ago

Per @nyck33's question here, I am trying to see if deep linking with my example app appearing to be working. However, I just realized that I am unsure about what to expect with oldBucket and how to restore my authState.

I did these steps.

I see deep linking was attempted by go_router but, because of the authStatus initialized, I ended up going to '/login' path.

@csells, could you review and advise how to use oldBucket for this use-case?

Performing hot restart...                                          252ms
Restarted application in 254ms.
|.. authState: AuthState(email: -, access_token: -, AuthStatus.unauthenticated)
|.. oldBucket null
\.... initialRestore true
GoRouter: known full paths for routes:
GoRouter:   => /
GoRouter:   => /polygon
GoRouter:   => /login
GoRouter: setting initial location /
|.. _routeToPath: /
\.... _authStatus: AuthStatus.unauthenticated
GoRouter: redirecting to /login
|.. _routeToPath: /login
\.... _authStatus: AuthStatus.unauthenticated
GoRouter: deep linking to /login
|.. _routeToPath: /login
\.... _authStatus: AuthStatus.unauthenticated
token 0002BIhGyCWXtb0YpIeRvED8TZ6R
GoRouter: going to /
|.. _routeToPath: /
\.... _authStatus: AuthStatus.authenticated
GoRouter: refreshing /
|.. _routeToPath: /
\.... _authStatus: AuthStatus.authenticated
|.. authState: AuthState(email: -, access_token: -, AuthStatus.unauthenticated)
|.. oldBucket null
\.... initialRestore true
GoRouter: known full paths for routes:
GoRouter:   => /
GoRouter:   => /polygon
GoRouter:   => /login
GoRouter: setting initial location /
|.. _routeToPath: /
\.... _authStatus: AuthStatus.unauthenticated
GoRouter: redirecting to /login
|.. _routeToPath: /login
\.... _authStatus: AuthStatus.unauthenticated
GoRouter: deep linking to /polygon
|.. _routeToPath: /polygon
\.... _authStatus: AuthStatus.unauthenticated
GoRouter: redirecting to /login
|.. _routeToPath: /login
\.... _authStatus: AuthStatus.unauthenticated
token 0002BIhGyCWXtb0YpIeRvED8TZ6R
csells commented 2 years ago

I'm not as familiar with state restoration as I should be. Perhaps this sample will be helpful?