-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[go_router] Prevent access to route when navigated to via a deep link #103659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you explain more on your use case? |
By default, any deep link is mapped to route configuration, even if route is not supposed to be accessed through deeplink. |
@chunhtai Yes I'm using Flutter Web and I want some routes to be accessed only by the user navigating "in-app" and not by entering the URL directly. For now I'm manually setting the extra argument to true when navigating in app, so I can differentiate between deeplinks or user navigation. |
Thanks for explanation, I think instead of add a boolean to the state, we should have a more comprehensive API to handle Deeplink For example GoRouter(
....
onDeepLink: (RouteInformation info) => ....
) and by default , it will go through the regular parsing if this method is not provided |
@chunhtai It's a good idea yes, but maybe the function onDeepLink should also be supported on each GoRoute(...). So we don't have to do some complicated "if else" or "switch case" for each routes we want to intercept in the global onDeepLink function. |
@chunhtai I need this feature also.
|
I would also like this feature, so I came to say my use case. My whole app consists of 3 screens: register -> waiting for approval -> approved / rejected. I made a workaround by using boolean which I set to true everytime I navigate using redirect: (state) {
// triggered by URL modification
if (!_routerNavigated) {
// allow app start
if (_router.location == '') {
return null;
// allow manual navigation to register screen
} else if (state.subloc.startsWith('/register')) {
return null;
// to prevent redirect loop
} else if (_router.location == state.subloc) {
return null;
// otherwise return back to the current location
} else {
return _router.location;
}
// triggered by GoRouter navigation
} else {
_routerNavigated = false;
}
return null;
} My other idea was some ability to allow ignoring URL bar completely. |
you can use redirect to always redirect to a different path. For the deeplink, right now browser backward and forward button are treated the same as deeplink. Although there is a way to differentiate them, they are really similar in nature. If app were to prevent deeplink access of a page, should the browser backward and forward button be prevented as well? |
We also have plan to improve overall deeplink setup process, the more flexible API we provide the less deeplink code we can automate for the developers. This requires more thoughts |
I think, the best would be to be able to do both depending on what we need. What I would do is in the redirect callback give access to a "RouterEvent" object witch contains informations about the event with properties like: inAppNavigation or urlNavigation, historyNavigation, deepLinkNavigation. Maybe using an enum or booleans. |
There is another issue to add support for handling deeplinks from different domains. #100624 We also need to expose domain information for deeplinks. One idea is that add a new string or something in the GoRouteState. If we do that, we can check the domain information and use that to determine if it is a deeplink. |
Hi, can we make automatic handling optional? I mean I want to run some preconditions and also want to push rather than go. |
I mean a notification comes and user is in a flow he taps and everything gone |
I think there are two steps to fix this issue
|
Hi, when is this scheduled to release ? I have the same requirement to restrict deeplink, without going through login page. |
You mention that you can tell whether a GoRouteState is a deep link by checking If so, the only way to tell if a state is a deep link or initiated from within the app is to add some extra denoting that it is not a deeplink, as others have suggested? |
@chunhtai I was able to get back a
I can get moving on making a PR for this if this makes sense to you... |
This is expected as of now, since go_router can't migrate to use RouteInformation.uri yet. Edit: looks like the stable has reach 3.12.0 and we should be able to use it now |
yes, feel free to send out a pr. |
Actually I was wrong package is supporting 3.10.0 and up, so the routeinformation.uri isn't yet available. update: just consulted with eco team, it looks like we can bump the version to latest stable if we want to. |
@chuntai So, we would need a PR that:
correct? |
@ChopinDavid that sounds correct |
PR is open @chunhtai: flutter/packages#5742 |
#5742) A number of developers have voiced the desire to be able to know whether a `GoRouterState` is the result of a deep-link or in-app navigation from within their `GoRouter`'s `redirect` method. This can be accomplished by exposing the `Uri`'s `scheme` and `host` on the `GoRouterState`. This way, we can know whether the `GoRouterState` is the result of a deep-link by checking `state.uri.scheme != null` or `state.uri.host != null`. This PR would close [#103659](flutter/flutter#103659 (comment)). No tests were broken as a result of this change, and we have added coverage for this change through new tests.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Use case
Prevent access to a route with deeplink.
In the redirect function I would like to detect if the navigation event is a deeplink and redirect to the parent route.
Proposal
Add a bool in the state that says if its deeplink or not
The text was updated successfully, but these errors were encountered: