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
441 stars 96 forks source link

How to implement PopUntil? #325

Closed bw-flagship closed 2 years ago

bw-flagship commented 2 years ago

Thanks for the remarkable package! Sometimes I want to pop all pages until I arrivte at my home page.

I found this way to implement it:

  void popUntil(bool Function(String) predicate) {
    while (!predicate(_router.routerDelegate.location)) {
      _router.pop();
    }
  }

popUntil((location) => !location.contains("home"));

This is not perfect because the location contains all the parameters, so I have to use the contains-operator. Is there any better way to archive this?

Thanks!

csells commented 2 years ago

You don't need to do that. A simple context.go('/') will replace the entire stack of pages with just your homepage.