Optional params/zero-length rest routes
See original GitHub issueVia this Stack Overflow question. It would be nice if there was a way to do optional parameters — e.g. /foo
, /fr/foo
and /ca/fr/foo
all resolving to the same page component (where fr
is a named lang
parameter and ca
is a named country
parameter).
@Timer from the Next.js team had a neat idea — we could mark optional parameters with double brackets: routes/[[country]]/[[lang]]/foo.svelte
At the same time, it might be nice if routes/[...parts]/foo.svelte
matched all those pathnames. At present it will match /fr/foo
and /ca/fr/foo
but not /foo
.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:20
- Comments:13 (6 by maintainers)
Top Results From Across the Web
RESTful API - Optional parameters and overloading vs. ...
Have a single route such as GET /api/resource with parameters for resourceId , resourceNumber and resourceCategory . Based on the parameters ...
Read more >Optional Parameters in ASP.NET Core Web API Routing
In a route template, an optional parameter is a URI or endpoint parameter that we can remove since default values have been supplied...
Read more >Consume REST Api with optional parameters
Hi,. I'm trying to create a rest api call that uses a lot of parameters. The api delivers a route between 2 points....
Read more >Adding Custom Routes to the WordPress REST API
The fourth and last argument is an optional boolean argument, called “override.” It is there to help deal with clashes that may occur ......
Read more >Oracle REST Data Services Route Patterns - Variously Noted
URI Templates match against the entire path & query string of a URI. There's no way to express that a parameter may be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I absolutely want this. It would simplify my search pages significantly - filesystem routes are not ideal for SEO!
I just tested this on my filesystem and it does seem to work - but it’s not extensive, obviously!
@jhwheeler my own approach at this time would be to open a RFC, link all of these issues, and detail:
I think from there you’d be in a good position to gather any required feedback, resistance, etc, in order to create a PR to add the syntax.