Closed mlars84 closed 2 years ago
The intialRoute isn't overridden with the deep link? Let me take a look.
I believe I had similar issue, but my problem was with redirection to /init
with ?from=/some-deep-link
for after init redirection. It behaved like this:
/some-deep-link
/init?from=/
/some-deep-link
.Log looks like this (I added DateTime.now()
at the top of the redirect
so you can see what happens when):
GoRouter: setting initial location /
[00:41:56.324] state.location: /
GoRouter: redirecting to /init?redirect=/
[00:41:56.326] state.location: /init?redirect=/
GoRouter: deep linking to /users
[00:41:56.599] state.location: /users
GoRouter: redirecting to /init?redirect=/users
[00:41:56.599] state.location: /init?redirect=/users
GoRouter: going to /users
[00:41:56.613] state.location: /users
I also found this. There's described exactly this behavior but on iOS platform, and on iOS this behavior is correct. My guess is it works the same on web?
I'm unable to duplicate the described behavior. deep linking to /page2
works as expected -- it goes right to that page w/o flashing any other pages.
https://user-images.githubusercontent.com/2568253/141213794-3a523c4f-e3af-456d-8389-cc6ad833b5de.mov
Interesting, I can see it in your example.
This is on latest commit in master branch. I'm on Flutter 2.7.0-3.1.pre, if that's anyhow useful.
to which example are you referring? it doesn't happen in the code you posted above that I can see.
I'm not OP, I just came to provide more input :)
OP used example from here and that's also what I ran and recorded.
Neither of these videos opens up a new tab and goes to the deep link as described by OP.
The point of opening a new tab is because this is happening only on "cold start". It's the same as just refreshing.
Here also slowed down so you can see how it exactly matches log messages
I believe I have the same issue. I will describe my use case here. I have an app where the user logs in with Google:
http://localhost:5000/#/web-login-callback?access_token=XXX
in the flutter appBut when I log out the router state in the global redirect
function, the first location that is called is /
, the initial route. Only after that is the user redirected to the original path without any query params.
@csells maybe you could confirm the issue by printing out the routes that are being handled by the redirect
function? You might also see the initial route as the first one, even though it should deep link directly into the app.
This issue is due to the fact that RouterDelegate.setInitialRoutePath
in asynchronous and is therefore not called before the first build. This means that during the first build, GoRouterDelegate
always uses GoRouter.initialLocation
. This can be viewed by adding print(matches)
in GoRouterDelegate._builder
.
So this is indeed linked only to "cold-start" which can be triggered either by navigating in a new tab or hitting the browser reload button.
This issue is tricky because it only appears when the number of pages shown by GoRouter.initialLocation
defers from the one that should be shown when deep-linking.
This is what happens in @leoshusar example:
initialLocation
is /
which has a page stack of [MaterialPage
]/page2
which has a page stack of [MaterialPage
, MaterialPage
]
Therefore, when GoRouter
first shows /
then /page2
the usual MaterialPage
enter transition plays.Fortunatly, there is an easy solution: Make GoRouterDelegate.setInitialRoutePath
synchronous ! To achieve this we need to:
SynchronousFuture
from GoRouterDelegate.setInitialRoutePath
SynchronousFuture
from GoRouteInformationParser
Point 1 is easy to deduce from Flutter RouterDelegate.setInitialRoutePath
however I had to dive in the Flutter implementation to see that using RouteInformationParser.SynchronousFuture
was also needed :wink: should be fixed in v2.2.7. @mlars84 and @lulupointu can you verify?
It's working as expected in v2.2.7
on my side.
I just started re-writing my app's routing to go_router and so far everything is great, docs are great, etc. The only issue I am having is that when attempting to deep link (or even just link to another route at all) the initial location always flashes first when opening a new tab. E.g., initial route is '/login'. Open a new tab and paste in http://localhost:5000/#/inbox for example and login screen will flash before re-directing to '/inbox'. I've re-created this with the example as well.
Take the above code, open a new tab and paste in http://localhost:5000/#/page2 or http://localhost:5000/#/asdf and you will see a flash of the home screen prior to being properly re-directed.
Browser is Chrome 95.0.4638.69 on a Mac OS running 11.6.