kadirahq / flow-router

Carefully Designed Client Side Router for Meteor
MIT License
1.09k stars 194 forks source link

Feature suggestion: FlowRouter.addQueryParams() #532

Closed SachaG closed 8 years ago

SachaG commented 8 years ago

I think it's a pretty common use case that you need to add or modify a query parameter without changing the ones that are already there. For example, if you're filtering a list you might first sort by date (http://site.com/list/?sort=date) then add a second filter without removing the first parameter (say, http://site.com/list/?sort=date&filter=active).

Is that something that might be supported by default by FR at some point? Or would you guys accept a PR?

EDIT: thinking about it some more, my use case it to get the path, not set it. So I'm not sure how that would fit in with FR's existing APIs? It would probably look something like this:

FlowRouter.extendPathWithQueryParams = (path, params, newQueryParams) => {
  const current = FlowRouter.current();
  const currentQueryParams = _.clone(current.queryParams);
  return FlowRouter.path(path, params, _.extend(currentQueryParams, newQueryParams));
};

Not sure how useful that actually is on second thought, so I'll close this for now :)