Closed noga-dev closed 2 years ago
The issue with history tracking/modifying is that this is quite limited in flutter web due to intrinsic limitation imposed by web browser. Here are what web browsers allow:
By blindly I mean: You can change to change the current history index by a certain amount (positive or negative) but you don't know whether this is possible, nor if modifying the current history index by the said amount would keep the user in your app.
If you take into account the fact that:
You end up with not much to implement.
However, if we consider other platform, anything can be done (since the app cannot be restarted). The question when implementing this feature should be how to deal with the discrepancies between web and non-web.
The web behavior makes me nuts trying to find a sensible way to handle browser forward/backward buttons so I just wrap everything in Router.neglect so that I can still get the URL to change and use deep links. I then maintain my own navigation history where it makes sense. Yeah it breaks the forwards / backwards buttons in the browser but I have found that to be less brittle and frustrating for users than trying to fight native browser behavior and losing.
So related to the original question, probably the only way to handle the discrepancies in platforms it to allow an opt out of browser history and substitute your own history stack.
I do think the tracking portion of this at least would be quite nice to have. Sometimes you make decisions based on the current state of the history stack, currently this requires adding a listener to the router and storing this List<String> history
yourself.
I can imagine exposing a history stack but I won't be exposing a way to handle the browser's history stack from go_router anytime soon.
Opening a separate issue, per @lulupointu's suggestion here: https://github.com/csells/go_router/issues/196#issuecomment-981360706
Go Router should have the ability to track nav history (kind of like Routemaster) and allow us to programmatically go back and forth and maybe also manipulate the stack.