You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[go_router] Support a history stack like in a web browser #115353
P3Issues that are less important to the Flutter projectc: proposalA detailed proposal for a change to Flutterp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team
Suppose we have an app where we need to keep track of the history, and let the user go back and forth between pages he navigates to. (For example a note taking application where notes can be linked together).
In practice we would have a back/forward button somewhere in the application (behaving like the one in a web browser), and we would like to keep scroll positions / states of the pages in the history.
I wonder how to implement this with go_router.
I did the following:
listen to navigation changes (store each path in a list)
call GoRouter.go every time I want to go back/forth in the history
This leads to the following issues:
page states are not preserved (scroll position)
animation between pages are strange. (we can probably use an animation that is similar for entering / leaving the page and the problem is solved)
I considered using push / pop but it doesn't seem designed that way. (not sure what they are useful for besides dialogs that cannot be deep linked to).
I suspect this is somehow linked to #99112 for navigating the history properly and being able to store the state.
This is also probably connected to #80303 for state restoration. (which is the main issue)
Reacted by Tobias Marschall, Ahmed Fwela, Kingkor Roy Tirtho, Zhukov Sergey, Zarechnev Maxim, Thomas Järvstrand, Francesco Iapicca, Jory Lenz, Boolean, Amir Panahandeh and 11 more
Hi @cgestes, I see that the browser's navigation buttons issue is discussed at #99112.
However, I'm not sure that issue will have a separate edged issue for the web (Discussion is still ongoing). You can leave there your comments/opinions.
Also, this issue seems to be the opposite of a proposal at #108114.
changed the title [-][go_router] How do we support a history stack like in a web browser?[/-][+][go_router] Support a history stack like in a web browser[/+]on Nov 16, 2022
Removing the web label for now because this is likely a go_router issue. However, if we need to fix something in the framework or in the engine, feel free to add the web label back.
we don't have a clear idea on how it would be used.
A common use case is the ability to go back after a redirection. EG you are redirected to /sign-in page and want to navigate back to the previous page when the user taps a back button.
In my case I have an events app where the details of a particular event are on the path /events/:id .
From the event details you can go to the profile details of people attending the event which are on the path /users/:id.
From the profile details page you can then see and visit other events the the user is attending, visit the details page of other users attending those other events and so on and so forth, creating a potentially infinite stack that crosses top-level path boundaries.
I'd love to be able to somehow declaratively manage this and still be able to use the back button.
Adding a comment because I'm facing a similar issue. I want to disable the browser history stack so that users can't swipe back from edge (to cause a reload).
For example my home page is myapp.com/login, and after signing in it goes to myapp.com/home.
But if the user swipes from the left edge then the app will navigate back to myapp.com/login, which I don't want to happen.
returning false with willpopscope doesn't help because this is the browser's functionality rather than the flutter materialapp gesture system
Adding a comment because I'm facing a similar issue. I want to disable the browser history stack so that users can't swipe back from edge (to cause a reload).
For example my home page is myapp.com/login, and after signing in it goes to myapp.com/home.
But if the user swipes from the left edge then the app will navigate back to myapp.com/login, which I don't want to happen.
returning false with willpopscope doesn't help because this is the browser's functionality rather than the flutter materialapp gesture system
How did you fixed this?
This can be fixed by providing the redirect parameter on the GoRouter constructor.
As explained on the docs: Redirection.
You could even use a queryParameter to save the path the user was trying to visit before being redirected to login, like so: https://baseUrl/login?from=/home.
P3Issues that are less important to the Flutter projectc: proposalA detailed proposal for a change to Flutterp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team
Activity
huycozy commentedon Nov 15, 2022
Hi @cgestes, I see that the browser's navigation buttons issue is discussed at #99112.
However, I'm not sure that issue will have a separate edged issue for the web (Discussion is still ongoing). You can leave there your comments/opinions.
Also, this issue seems to be the opposite of a proposal at #108114.
cgestes commentedon Nov 15, 2022
Hi @huycozy, thanks for answering and for pointing out #108114 :D
I need the exact reverse, full history both on the web and in app!
huycozy commentedon Nov 16, 2022
Hi @cgestes, I label this issue as a proposal for further insights from the team as I'm not sure how it will be dealt with issue #108114. Thanks!
[-][go_router] How do we support a history stack like in a web browser?[/-][+][go_router] Support a history stack like in a web browser[/+]yjbanov commentedon Nov 17, 2022
Removing the web label for now because this is likely a go_router issue. However, if we need to fix something in the framework or in the engine, feel free to add the web label back.
18 remaining items
TekExplorer commentedon Dec 15, 2023
@getBoolean recent versions of riverpod do not recommend the use of
StateNotifierinstead, useNotifiergetBoolean commentedon Dec 15, 2023
@TekExplorer Thanks, I updated the code
cedvdb commentedon Jan 21, 2024
A common use case is the ability to go back after a redirection. EG you are redirected to
/sign-inpage and want to navigate back to the previous page when the user taps a back button.tjarvstrand commentedon Jan 24, 2024
In my case I have an events app where the details of a particular event are on the path
/events/:id.From the event details you can go to the profile details of people attending the event which are on the path
/users/:id.From the profile details page you can then see and visit other events the the user is attending, visit the details page of other users attending those other events and so on and so forth, creating a potentially infinite stack that crosses top-level path boundaries.
I'd love to be able to somehow declaratively manage this and still be able to use the back button.
rahul-sysquare commentedon Oct 24, 2024
How did you fixed this?
OppositeDragon commentedon Aug 23, 2025
This can be fixed by providing the
redirectparameter on theGoRouterconstructor.As explained on the docs: Redirection.
You could even use a
queryParameterto save the path the user was trying to visit before being redirected to login, like so:https://baseUrl/login?from=/home.