question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optional params/zero-length rest routes

See original GitHub issue

Via 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:closed
  • Created 4 years ago
  • Reactions:20
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
antonycommented, Jun 30, 2019

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!

/routes/[country?]/[lang?]/foo.svelte
1reaction
antonycommented, Aug 14, 2020

@jhwheeler my own approach at this time would be to open a RFC, link all of these issues, and detail:

  1. The new route options you would like to see
  2. Alternatives for mapping syntax
  3. The proposed syntax for those route changes
  4. A part on how breaking this is in terms of people’s existing codebase
  5. OS compatibility (Windows / Linux / Mac)

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found