csells / go_router

The purpose of the go_router for Flutter is to use declarative routes to reduce complexity, regardless of the platform you're targeting (mobile, web, desktop), handling deep linking from Android, iOS and the web while still allowing an easy-to-use developer experience.
https://gorouter.dev
442 stars 96 forks source link

Provide a way to replace routes #60

Closed Zazo032 closed 2 years ago

Zazo032 commented 2 years ago

Currently, there's no .pushReplacement compatible API for replacing the current route

Moussenger commented 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?

Zazo032 commented 2 years ago

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)

Moussenger commented 2 years ago

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.

Zazo032 commented 2 years ago

Thanks! Will try that 😁