tatethurston / nextjs-routes

Type safe routing for Next.js
MIT License
571 stars 23 forks source link

Catch-all routes aren't generated right when the name isn't a valid JS identifier but is a valid NextJS route #49

Closed OliverDudgeon closed 2 years ago

OliverDudgeon commented 2 years ago

If I have an route which catches all subpaths such as "/api/as-api/[...as-proxy]" the generated route is { pathname: "/api/as-api/[...as-proxy]"; query: Query<{ as-proxy: string[] }> }. Notice that there is a key, as-proxy, which is missing quotes to allow it to be a valid object key.

Using v0.0.18

tatethurston commented 2 years ago

Thanks for reporting this @OliverDudgeon.

Thinking on the solution, we could quote all user supplied segments, or try to determine the subset that aren’t valid JS identifiers.

tatethurston commented 2 years ago

Out of curiosity, why do you prefer as-proxy overasProxy? The former will be less ergonomic in your code, and it’s not exposed to end users.

OliverDudgeon commented 2 years ago

Nothing preventing this for me