Closed superakabo closed 2 years ago
Building some logic around a previousLocation
can be tricky. Here is why: what happens when the browser back/forward button is pressed?
Building some logic around a
previousLocation
can be tricky. Here is why: what happens when the browser back/forward button is pressed?
It shouldn't be updated until a new/different route is pushed.
It shouldn't be updated until a new/different route is pushed.
Mmm I'm not sure this is desirable. My question was rather between (in the case of pressing the back button):
previousLocations
previousLocations
<- This is basically how browser history workAlso the behavior described above if for a simple back button press but mind that on the web user can do really what they want.
Here is another interesting question: what happens if the user reload the page on the web? The app is restarted so the state is lost therefore previousLocations
has to be empty right ? This is a weird and unexpected behavior (if you try to rely on this to display the unique button to get out of the page for example).
I'm not saying it's not possible. Choices can be made and a system could work. The issue is that what you end up would not be very intuitive and would behave weirdly in certain edge cases (which the dev might not take into account before a user run into the issue, which is the worse kind of bugs)
It shouldn't be updated until a new/different route is pushed.
Mmm I'm not sure this is desirable. My question was rather between (in the case of pressing the back button):
* Adding the new url and appending the previous to `previousLocations` * Removing the last element of `previousLocations` <- This is basically how browser history work
Also the behavior described above if for a simple back button press but mind that on the web user can do really what they want.
Here is another interesting question: what happens if the user reload the page on the web? The app is restarted so the state is lost therefore
previousLocations
has to be empty right ? This is a weird and unexpected behavior (if you try to rely on this to display the unique button to get out of the page for example).I'm not saying it's not possible. Choices can be made and a system could work. The issue is that what you end up would not be very intuitive and would behave weirdly in certain edge cases (which the dev might not take into account before a user run into the issue, which is the worse kind of bugs)
OK.
@superakabo this functionality should be accessible to you by passing in a NavigatorObserver
object. You can see that in action in the following example: https://github.com/csells/go_router/blob/main/go_router/example/lib/nav_observer.dart
It is very easy to get the current location by doing
It will be nice to have a simpler implementation for the previous location(s) as well by doing