flutternavigationflutter-go-routergorouter

go_router - how to push a page over existing pages in stack (in any path)


I use go_router for navigation handling in my project. I have an invoice page, and I want to show this page after payment is done over existing pages on navigation stack.

For example, if the user is in /detail/book, /profile/job, or whatever path, I want to push that invoice page over all of my route paths with a back button on it to get back to the previous page.

I tried doing this manually with Navigator 2, but I don't know how to do it with Go Router.


Solution

  • Per the go_router documentation context.go('route') navigates to route by replacing stack of views context.push('route') navigates to route by adding view to the stack which can be removed by the back button you want with context.pop()