Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] Add query string support #11

Closed
egelja opened this issue Feb 18, 2022 · 2 comments
Closed

[FEATURE REQUEST] Add query string support #11

egelja opened this issue Feb 18, 2022 · 2 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@egelja
Copy link

egelja commented Feb 18, 2022

Describe the bug

Discussions are not enabled so I am using this.

There is a similar library to this, Remix Routes, that supports adding query parameters to URLs with the path helper. Could this functionality be added to this package?

Your Example Website or App

https://github.com/yesmeck/remix-routes

Steps to Reproduce the Bug or Issue

N/A

Expected behavior

Query parameters can be added to the path with the helper.

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

No response

@sandulat sandulat added enhancement New feature or request question Further information is requested labels Feb 20, 2022
@sandulat
Copy link
Owner

sandulat commented Feb 20, 2022

Hey @MrAwesomeRocks, thank you very much for your proposal!

Can't this be easily achieved with string literals for example?

`${route("/products")}?page=1`

`${route("/products/:id", { id: "123" })}?foo=bar`

I'm fine with adding query strings support to the package, but I'm not sure about the implementation.

AFAIK, since remix-routes actually generates a JS file (not just type annotations), containing all the routes with their params, they're able to do runtime checks and accept 2 or 3 parameters in their $path helper, depending on the route having or not having params (please see https://github.com/yesmeck/remix-routes/blob/fd892026329e97a0514a75f8e17ab4d8633849f3/src/index.ts#L1)

For example:

$path("/home", { foo: "bar" }) - appends foo as a query string (a runtime check was done here)
$path("/product/:id", { id: "1" }, { foo: "bar" }) - appends foo as a query string (a runtime check was done here)

I'm not really sure if we can achieve the same usage interface, since we're just exporting type annotations and we're not doing any runtime checks.

So basically there are 2 questions:

  • Do we need this at all if we can achieve this with string literals? Those parameters are not strongly typed anyway, so what's the benefit of passing them via an object instead of a string concatination?
  • If we want this, what would be the interface for setting query strings (taking into consideration that we're just exporting type annotations and we can't know if the second parameter of the route function is actually an object of parameters or query parameters)?

@sandulat
Copy link
Owner

sandulat commented Apr 8, 2022

I've created a discussion on this topic: #16

Let's use the Issues feature for tracking issues and Discussions for ideas/enhancements/etc.

@sandulat sandulat closed this as completed Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants