tomgilder / routemaster

Easy-to-use Navigator 2.0 router for web, mobile and desktop. URL-based routing, simple navigation of tabs and nested routes.
https://pub.dev/packages/routemaster
MIT License
327 stars 61 forks source link

Make it easier to change part of current path #124

Open tomgilder opened 3 years ago

tomgilder commented 3 years ago

It would be nice if it's easier to alter the current path, such as changing one query parameter.

For instance if the user is on /search?q=blah&order=popular and we want to change to /products?q=blah&order=recent, currently you have to change the entire URL:

Routemaster.of(context).push('/search', queryParameters: {'order': 'recent', 'q': query});

We could make currentRoute writeable and add a copyWith:

final routemaster = Routemaster.of(context);
routemaster.currentRoute = routemaster.currentRoute.copyWith(
  queryParameters: {
    'order': 'recent',
    'q': query
  }
);

We could make .push() nullable (but I really don't like this):

Routemaster.of(context).push(null, queryParameters: {'order': 'recent', 'q': query});

...or there could be an entire new method.

But it would be nice if somehow you could just update one parameter, not have to create a new map with all of them.

tomgilder commented 3 years ago

There could also be Routemaster.of(context).updateRoute((route) => route.copyWith(...))

tomgilder commented 3 years ago

Or adding a pushRoute method: Routemaster.of(context).pushRoute(RouteData.of(context).copyWith(...))

rnl-veolys commented 3 years ago

or Routemaster.of(context).updateRoute(queryParameters: {'order': 'recent', 'q': query}); ?

because I think push is unclear.