-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Use case
Problem
The go_router package provides a great mechanism for handling deep links through the redirect callback. However, there are scenarios where a deep link should trigger an action (e.g., saving a referral code, showing a snack bar) without navigating to any route or modifying the current screen.
Currently, the redirect function requires returning either null (to proceed to the intended route) or another string (to redirect to a different route). There is no clean way to "do nothing" while still handling the deep link logic.
Use Case
An example is a referral link (/referral?code=XYZ123) that should:
- Save the referral code locally.
- Show a snack bar confirming the referral code was saved.
- Prevent navigation, keeping the user on their current screen.
Proposal
-
Introduce a separate
onDeepLinkcallback that is triggered for every incoming deep link. This callback could be used to handle action-based links independently of routing.GoRouter( onDeepLink: (context, state) { if (state.uri.path == '/referral') { // Perform the action here return true; // Handled successfully } return false; // Continue with routing }, // Other configurations... );
-
Provide a mechanism to block/prevent navigation dynamically based on deep link conditions.
redirect: (context, state) { if (state.host.isNotEmpty && state.uri.path == '/referral') { // Perform the action and block navigation } return null; }