sandulat / routes-gen

Framework agnostic routes typings generator. Remix ☑️ SolidStart ☑️
MIT License
283 stars 12 forks source link

[FEATURE REQUEST] Add query string support #11

Closed egelja closed 2 years ago

egelja commented 2 years ago

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

Additional context

No response

sandulat commented 2 years ago

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:

sandulat commented 2 years ago

I've created a discussion on this topic: https://github.com/sandulat/routes-gen/discussions/16

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