You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[go_router] Prevent access to route when navigated to via a deep link #103659
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
By default, any deep link is mapped to route configuration, even if route is not supposed to be accessed through deeplink.
I suppose OP wants to disable deep linking to some pages. @chunhtai
@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.
and by default , it will go through the regular parsing if this method is not provided
Reacted by ankitparmar007, Iskander Shamsudinov, Robert Heim, Anton Stubenbord, bvoq, brendanatlifewise, Bram Musters, Acácio Veit Schneider, Philippe Dupuis, Berdrigue and 16 more
@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.
But it maybe more suitable with a wider concept rather than deeplink merely.
The wider concept is preventing an access going forward.
By the way, is there any other method to prevent an access?
Thanks for explanation, I think instead of add a boolean to the state, we should have a more comprehensive API to handle Deeplink
You mention that you can tell whether a GoRouteState is a deep link by checking GoRouteState.uri.host and GoRouteState.uri.scheme. Both of these values are "" when I check them in the redirect, does this sound right?
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 GoRouteState.uri.host and GoRouteState.uri.scheme in our redirect with, seemingly, no side-effects by making the following changes:
You mention that you can tell whether a GoRouteState is a deep link by checking GoRouteState.uri.host and GoRouteState.uri.scheme. Both of these values are "" when I check them in the redirect, does this sound right?
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
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 flutter doctor -v and a minimal reproduction of the issue.
Activity
chunhtai commentedon May 19, 2022
Can you explain more on your use case?
vimhead commentedon May 20, 2022
By default, any deep link is mapped to route configuration, even if route is not supposed to be accessed through deeplink.
I suppose OP wants to disable deep linking to some pages. @chunhtai
DamienMrtl commentedon May 23, 2022
@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.
chunhtai commentedon May 23, 2022
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
and by default , it will go through the regular parsing if this method is not provided
DamienMrtl commentedon May 23, 2022
@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.
horo99 commentedon Jun 13, 2022
@chunhtai I need this feature also.
But it maybe more suitable with a wider concept rather than deeplink merely.
The wider concept is preventing an access going forward.
By the way, is there any other method to prevent an access?
13 remaining items
chunhtai commentedon Jul 21, 2023
I think there are two steps to fix this issue
This adds the ability to know whether a GoRouteState is a deeplink (by checking GoRouteState.uri.host and GoRouteState.uri.scheme)
The onenter and onexit should have more flexible api to decide whether to push page or doing other operation.
Harris-Thomas commentedon Oct 28, 2023
Hi, when is this scheduled to release ? I have the same requirement to restrict deeplink, without going through login page.
ChopinDavid commentedon Dec 15, 2023
You mention that you can tell whether a GoRouteState is a deep link by checking
GoRouteState.uri.hostandGoRouteState.uri.scheme. Both of these values are""when I check them in theredirect, does this sound right?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?
ChopinDavid commentedon Dec 17, 2023
@chunhtai I was able to get back a
GoRouteState.uri.hostandGoRouteState.uri.schemein ourredirectwith, seemingly, no side-effects by making the following changes:parser.dart:configuration.findMatch(routeInformation.location!, extra: state.extra);changes toconfiguration.findMatch(routeInformation.uri.toString(), extra: state.extra);information_provider.dart:location: routeInformation.location,changes touri: routeInformation.uri,I can get moving on making a PR for this if this makes sense to you...
chunhtai commentedon Dec 18, 2023
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
chunhtai commentedon Dec 18, 2023
yes, feel free to send out a pr.
chunhtai commentedon Dec 18, 2023
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.
ChopinDavid commentedon Dec 19, 2023
@chuntai So, we would need a PR that:
RouteInformation.uriexists)RouteInformation.urirather thanRouteInformation.locationcorrect?
chunhtai commentedon Dec 20, 2023
@ChopinDavid that sounds correct
ChopinDavid commentedon Dec 22, 2023
PR is open @chunhtai: flutter/packages#5742
[go_router] Expose full `Uri` on `GoRouterState` in `GoRouterRedirect` (
github-actions commentedon Feb 23, 2024
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
flutter doctor -vand a minimal reproduction of the issue.