-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[go_router] Support for top level onEnter
callback.
#8339
base: main
Are you sure you want to change the base?
Conversation
Added onEnter callback to enable route interception and demonstrate usage in example.
Hi @chunhtai, This PR introduces a top-level onEnter callback, addressing critical gap in go_router’s handling of deep links and redirect customizations. It allows developers to intercept routes, block navigation, or implement custom logic. Given its potential impact, your feedback would be greatly appreciated. Thank you for your time! |
/// }, | ||
/// ); | ||
/// ``` | ||
final OnEnter? onEnter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is more powerful, we should deprecate redirect. fyi there is also this https://docs.google.com/document/d/1L940WGrM1YJ8BkJEpNd67fUqoqC6OsTfch4eH86E0xU/edit?resourcekey=0-9oxsWU1tLpAACTUXyNjpkA&tab=t.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @chunhtai Thanks for sharing the design doc! After reviewing it, I have some thoughts on how we can potentially combine approaches:
- For the current PR, we could enhance the
onEnter
callback signature to match the guard pattern:
typedef OnEnter = bool Function(
BuildContext context,
GoRouterState currentState,
GoRouterState nextState
);
-
This would make it easier to later migrate to the guard-based approach while solving the immediate need. The boolean return could map to Resolution.next (true) and Resolution.stop (false).
-
The guard system looks like a more complete solution for the long term, but the current
onEnter
approach could serve as a simpler solution that:- Handles the action-based deeplinks case.
- Provides access to router operations.
- Allows splash screen handling through router access.
- Maintains backward compatibility.
Would you prefer, I update the PR to use this enhanced signature?
Description:
This PR introduces top level
onEnter
callback inRouteConfiguration
to allow developers to intercept and conditionally block navigation based on incoming routes. It adds an example (top_level_on_enter.dart
) demonstrating its usage, such as handling referral code from/referral
.What This PR Changes:
onEnter
callback (typedef OnEnter
) to intercept route navigation before processing.onEnter
inGoRouteInformationParser
.RouteConfiguration
to include theonEnter
callback.top_level_on_enter.dart
, to demonstrate the feature.onEnter
callback functionality.Simple usage example:
Impact:
Enables developers to implement route-specific logic, such as support for handling action-based deep links without navigation (160602)
Pre-launch Checklist:
dart format
.)[go_router]
.pubspec.yaml
with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes].CHANGELOG.md
to add a description of the change, [following repository CHANGELOG style], or this PR is [exempt from CHANGELOG changes].///
).