Repository navigation
Open
Labels
P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Fluttercustomer: crowdAffects or could affect many people, though not necessarily a specific customer.p: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team
Description
I would like to choose in redirect method if i want to clear a navigation history (as it is in context.go), even if i started navigation with context.push.
Use case
On application start i have a few configuration pages that user setup once, and finally ends up in dashboard page.
Possible navigation flows (depend on what user already setup, and what skipped in the past):
'/' -> '/dashboard'
'/' -> '/language' -> '/dashboard'
'/' -> '/welcome'/ -> '/dashboard'
'/' -> '/welcome'/ -> '/language' -> '/dashboard'
In language page i want to have a back button in appbar and be able to pop page. When i ends up in dashboard i would like to have a clear navigation history.
Proposal
- There could be a
Redirectionclass, withclearHistoryparameter (falseby default).
GoRoute(
path: '/language,
builder: (_, __) => const LanguagePage(),
redirect: (_, __) {
final skipToDashboard = ...;
if (skipToDashboard) {
return Redirection('/dashboard', clearHistory: true);
}
return null;
}
),
- Add
clearHistorymethod toGoRouterclass.
Reacted by Akshar Patel, Matthieu Rosset, Ahmad Khan, Phil, gdurandrexel, glarusgaurav, harkairt, lvsecoto, Arthur Nascimento, khwgit and 48 more
Reacted by Maher, Kelvin Wieth and Roc Boronat
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Fluttercustomer: crowdAffects or could affect many people, though not necessarily a specific customer.p: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team
Type
Projects
- StatusShow more project fieldsNo status
Activity
exaby73 commentedon Oct 27, 2022
Hello @dzziwny. Thank you for filing this request. Labelling the issue for visibility and insights from the team
chunhtai commentedon Oct 27, 2022
you can have a top level route and use go to clear the history.
dzziwny commentedon Oct 28, 2022
You mean, the top route over setup pages, like for ex.
/setup/language? But if i go from/setup/welcometo/setup/languagei need to usepushanyway, right? The problem is that i don't want to decide from any setup page wether to usepushorgo- I am doing it now and have a separated service that resolves the next step and decide which method to use - it works but looks ugly andredirectlost any sense.hunterwilhelm commentedon Nov 29, 2022
Sometimes
redirectdoes apopUntil. Demonstrated in #116164.Could we add a way to choose between
push,go, andpopUntiltoo?37 remaining items
Sukarma33 commentedon Dec 12, 2024
I have the same issue, have you found the solution?
christo-caddayn commentedon Feb 13, 2025
I did a workaround. I don't know wheter it suits other usecases.
FutureOr<String?> redirect(BuildContext context, GoRouterState state) async {
if (!isAppLatest) { // REDIRECTION CONDITION
final p = 'my-path-to/screen';
String data = 'sample data';
}
}
I know this is not the best way. Just posting here so that anyone looking for workarounds can try this.
abdullahrs commentedon Feb 19, 2025
This feature is crucial for complex deep-linking scenarios. Simply redirecting to the given location causes the loss of the existing navigation stack.
chunhtai commentedon Feb 19, 2025
This pr should support this feature flutter/packages#8339
omar-hanafy commentedon Oct 26, 2025
Status update:
Top-level
onEntershipped in go_router 16.3.0 (PR #8339). It lets apps intercept incoming navigation, implement deep-link handling without page renders, and decide push vs go semantics before legacy redirects and route-level redirects run.@chunhtai, I think we might close this as completed.
curiosissimoz commentedon Nov 16, 2026
I don't think we can mark this as completed, since the user who opened this issue asked not for a global
onEnter, but for a per-routeonEnter.