Skip to content

[go_router] Support a history stack like in a web browser #115353

Open

Description

@cgestes

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)

Activity

  1. added
    in triage
    on Nov 15, 2022
  2. huycozy commented on Nov 15, 2022

    @huycozy
    Member

    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.

  3. added
    waiting for response
    on Nov 15, 2022
  4. cgestes commented on Nov 15, 2022

    @cgestes
    ContributorAuthor

    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!

  5. removed
    waiting for response
    on Nov 15, 2022
  6. huycozy commented on Nov 16, 2022

    @huycozy
    Member

    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!

  7. added
    platform-web
    package
    c: proposal
    p: go_router
    and removed
    in triage
    on Nov 16, 2022
  8. 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
  9. removed
    platform-web
    on Nov 17, 2022
  10. yjbanov commented on Nov 17, 2022

    @yjbanov
    Contributor

    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.

  11. 18 remaining items

  12. TekExplorer commented on Dec 15, 2023

    @TekExplorer

    @getBoolean recent versions of riverpod do not recommend the use of StateNotifier instead, use Notifier

  13. getBoolean commented on Dec 15, 2023

    @getBoolean

    @TekExplorer Thanks, I updated the code

  14. cedvdb commented on Jan 21, 2024

    @cedvdb
    Contributor

    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.

  15. tjarvstrand commented on Jan 24, 2024

    @tjarvstrand

    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.

  16. rahul-sysquare commented on Oct 24, 2024

    @rahul-sysquare

    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?

  17. added
    team-framework
    triaged-framework
    and removed on Jun 5, 2025
  18. OppositeDragon commented on Aug 23, 2025

    @OppositeDragon

    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.

  19. added
    team-ecosystem
    triaged-ecosystem
    and removed
    team-framework
    triaged-framework
    on Aug 26, 2026
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

    P3c: proposalp: go_routerpackageteam-ecosystemtriaged-ecosystem

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions