Skip to content

[go_router] Support for Handling Action-Based Deep Links Without Navigation #160602

@omar-hanafy

Description

@omar-hanafy

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:

  1. Save the referral code locally.
  2. Show a snack bar confirming the referral code was saved.
  3. Prevent navigation, keeping the user on their current screen.

Proposal

  1. Introduce a separate onDeepLink callback 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...
    );
  2. 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;
    }

Metadata

Metadata

Assignees

Labels

Bot is counting down the days until it unassigns the issueP2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions