route-recognizer icon indicating copy to clipboard operation
route-recognizer copied to clipboard

Recognizing routes with queryParams

Open CamonZ opened this issue 10 years ago • 11 comments

Hi, over at @stackbuilders/all we're using route-recognizer as part of pretender.js to test an Ember app.

We have a complex scenario we're we are calling a backend endpoint with different query params to get a filtered collection of items leaving us with very complex test code where we map the params to what the responses should be.

From looking at the code of the library you guys are already adding the endpoint with the query params but when recognizing it you guys are dropping the query params leaving the recognize without viable solutions because it can't find any handlers for the route without the query params

Is this the intended behaviour, would making a patch for it to match the url with the queryParams make sense to you?

EDIT: Updated the code references to v0.1.9 which was the version used at the time I reported this.

CamonZ avatar May 04 '15 18:05 CamonZ

@CamonZ can you share some code, or a failing test case? Curious to learn more about this use case.

jamesplease avatar Apr 14 '16 20:04 jamesplease

Failing test as an Ember app: https://github.com/nathanhammond/rrtest-app

nathanhammond avatar Aug 10 '16 19:08 nathanhammond

Is there any update on this issue ?

I encounter the same problem while using pretender.js : I'd like to use different stubs for the same route but different query parameters with no luck.

lcoq avatar Dec 07 '16 11:12 lcoq

@jmeas it's been a while, I'd have to dig, and see if I have the failing code somewhere.

From my original description, it looks like the issue was that

  • /foo?bar=baz
  • /foo?quux=fgs

Were both being recognized simply as: /foo.

CamonZ avatar Dec 07 '16 11:12 CamonZ

@CamonZ @jmeas : @nathanhammond wrote a failing test as an Ember app few comments above, not sure if this is still relevant.

Anyway, I did not dig into the route-recognizer source code, but my use case with Pretender is the following :

When I try to stub a request on Pretender.js which includes query params (see code below), the request is not handled :

server.get('foo?bar=baz', /* ... */);

From what is said on this Pretender issue, Pretender needs some changes on route-recognizer to resolve this use case.

lcoq avatar Dec 07 '16 12:12 lcoq

I just got into this trap. This either needs to be supported or clearly documented under some sort of caveats section.

raido avatar Dec 15 '16 11:12 raido

I've also just come across this issue while trying to use Pretender.js with query params in my URL. Was there any progress made on a fix or is there anything that I can do to help it along?

patocallaghan avatar Mar 05 '18 23:03 patocallaghan

I came across this issue recently too while working with Pretender. I would be happy to move this forward with a PR but wanted to ask if this is something that would be ok for route recognizer to support before doing the work?

eddie-ruva avatar Mar 30 '18 05:03 eddie-ruva

Bumping this as I've also encountered it while using Pretender.js. Is there any update on this?

mattdonnelly avatar May 29 '18 09:05 mattdonnelly

I feel query params should not be a part of a route definition. At least I can't recall any MVC Framework which allows you to map routes to something other than URL pathname.

ro0gr avatar May 31 '18 18:05 ro0gr