Skip to content

[go_router] Replace redirect with onEnter and onExit #102408

@johnpryan

Description

@johnpryan
Contributor

In order to better support redirection, we should replace the redirection API with onEnter and onExit.

The onEnter function is called when the new location results in a RouteMatch that was not previously present on RouteMatchList:

matchList = [ "/a"]
matchList' = [ "/a", "b"]

When matchList changes to matchList', the onEnter callback for Route "b" will be called, and the callback for "/a" will not.

The onExit callback is invoked when the reverse is true:

matchList = [ "/a", "b"]
matchList' = [ "/a"]

When matchList changes to matchList', the onExit callback for Route "b" will be called.

Activity

added
c: new featureNothing broken; request for a new capability
P3Issues that are less important to the Flutter project
on Apr 22, 2022
changed the title [-]Add hook for when routes are removed[/-] [+]Add onExit callback[/+] on Apr 22, 2022
changed the title [-]Add onExit callback[/-] [+]Replace redirect with onEnter and onExit[/+] on Jul 22, 2022
changed the title [-]Replace redirect with onEnter and onExit[/-] [+][go_router] Replace redirect with onEnter and onExit[/+] on Jul 22, 2022
ElteHupkes

ElteHupkes commented on Sep 21, 2022

@ElteHupkes

Would it be possible to cancel / delay the route change through these callbacks? I feel like this could be a good mechanism to prevent route changes in case, for instance, a user has unsaved changes on the page you might want to warn them about.

johnpryan

johnpryan commented on Sep 22, 2022

@johnpryan
ContributorAuthor

Yes, onExit would support this scenario, similar to how you would use WillPopScope. (WillPopScope doesn't work with page-backed routes, which built by the Router / go_router)

AceChen1

AceChen1 commented on Nov 25, 2022

@AceChen1

@chunhtai @johnpryan Hi guys, as we know, android app usually have a common requirement: when user on the root router, and then click the physical backward, will have a tips "click again to exist the app". previous navigator 1.0, i can use WillPopScope to listen & control the true/false to implement it, but i don't know how to implement it on the go router, any advice?

105 remaining items

flutter-triage-bot

flutter-triage-bot commented on Dec 30, 2024

@flutter-triage-bot

This issue was assigned to @chunhtai but has had no status updates in a long time. To remove any ambiguity about whether the issue is being worked on, the assignee was removed.

removed
Bot is counting down the days until it unassigns the issue
on Dec 30, 2024
added
P2Important issues not at the top of the work list
and removed
P1High-priority issues at the top of the work list
on Jan 23, 2025
bogdanChernichenko

bogdanChernichenko commented on May 10, 2025

@bogdanChernichenko

So I guess no progress here?

omar-hanafy

omar-hanafy commented on May 10, 2025

@omar-hanafy

@bogdanChernichenko not really. We are making some progress in the top level on enter here

flutter-triage-bot

flutter-triage-bot commented on Jun 5, 2025

@flutter-triage-bot

The triaged-go_router label is irrelevant if there is no team-go_router label or fyi-go_router label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilityp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @stuartmorgan-g@Hixie@elitree@ElteHupkes@ManuelRauber

        Issue actions

          [go_router] Replace redirect with onEnter and onExit · Issue #102408 · flutter/flutter