Closed Zazo032 closed 2 years ago
You can replace the current route just routing to a new one.
If you are in /path/1/other
and wanted to replace other
by new
, you can just navigate to /path/1/new
. Also, if you want to replace 1/other
by just 2
, you can just navigate to /path/2
.
Is this what you are looking for?
So, imagine I'm in the home route, but I want to replace it with the login route (after logging out). Previously, calling pushReplacement
removed home route from the navigation stack and only the login route was available. With go_router
, if I'm in the home route (/
) and I push the login route (/login
), will it replace the home route? (e.g. no back button in app bar)
Yes. You are going to generate a new stack with each new route that doesn't match with the previous one.
If you are in /
and wanted to go /login
, you will go to that page being replaced the route. If you want to have the back stack, then you need to declarete /login
as a subroute of /
. This way, when you go to /login
, you will generate an stack with /
and then /login
.
You can check the named routes example to see how this works with subroutes generating stack and a login page that replace it.
Thanks! Will try that 😁
Currently, there's no
.pushReplacement
compatible API for replacing the current route