scottrippey / next-router-mock

Mock implementation of the Next.js Router
MIT License
400 stars 38 forks source link

add support for search prop #120

Closed jmisasa closed 6 months ago

jmisasa commented 6 months ago

This PR adds support for search prop which while using the library we noticed it was yet not supported

Thanks a lot for this amazing package!

changeset-bot[bot] commented 6 months ago

🦋 Changeset detected

Latest commit: 5afd47b61b74bc25e13644051a15f762817462dd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ---------------- | ----- | | next-router-mock | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

jmisasa commented 6 months ago

I noticed this PR https://github.com/scottrippey/next-router-mock/pull/82 where node dependencies were eliminated. I just pushed some new changes that should address this.

Didn't go with straight URLSearchParams because of the "bracket" notation required to parse a URL that contains multiple values for the same key

With query-string this behaviour is allowed:

import queryString from 'query-string';

queryString.parse('foo=1&foo=2&foo=3');
//=> {foo: ['1', '2', '3']}

Happy to read your thoughts. Thank you!


EDIT: ah pushed commit is messed up because it still uses node querystring and not query-string! when switching there seems to be some issue with types. Marked as draft and will have a clearer look at this after a good night sleep

jmisasa commented 6 months ago

ended up removing external dependency and used parsedUrl directly, feels kind of hacky but seems to do the trick. Thanks again!