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.

Dynamic Route Parameters Options

See original GitHub issue

Is your feature request related to a problem? Please describe. So, I’m using a dynamic route in a file /path/[slug]-[id].svelte. If I navigate to /path/foo-1, the variables are assigned as follows

slug === “foo” id === “1”

Instead, when I navigate to /path/foo1-foo2-1, then the variables are assigned as follows

slug === “foo1” id === “foo2-1”

Describe the solution you’d like What I expect is for the first dynamic parameter to match the longest possible pattern. Otherwise, at least, have a way to specify it. For instance the regex [a-zA-Z-]*-[a-zA-Z] matches the pattern with the last characters after - to be in the second part, but this is not a valid name for a file.

Also, the docs IMHO could be more extensive regarding this subject.

Describe alternatives you’ve considered One can match the entire part of the route and then split it.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
Conduitrycommented, Apr 28, 2021

One of the reasons for implementing route fallthrough was so that we could get rid of Sapper’s regex route params.

I don’t have strong opinions about how to resolve this. Maybe it would be nice for SvelteKit to provide all different partitionings of the path and try them in some arbitrary order, but that sounds annoying.

A simpler solution would be to pick one way to handle this, document it, and also document that if people want different behavior, they can use a single param for the folder name or filename and then do their own splitting and fall through if appropriate.

1reaction
GrygrFlzrcommented, Apr 29, 2021

the developer has then to redirect to a 404 Not found url

We can already take advantage of fallthrough by not returning in the load function, so non-matches would already turn into a 404.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic Routing - Gridsome
Dynamic pages are used for client-side routing. Route parameters can be placed in file and directory names by wrapping the name in square...
Read more >
Dynamic Routes - Next.js
Dynamic Routes are pages that allow you to add custom params to your URLs. Start creating Dynamic Routes and learn more here.
Read more >
How To Pass Multiple Route Parameters in a React URL Path
Route params are parameters whose values are set dynamically in a page's URL. This allows a route to render the same component while...
Read more >
Dynamic Route Matching with Params - Vue Router
Vue Router uses its own path matching syntax, inspired by the one used by express , so it supports many advanced matching patterns...
Read more >
How can I specify the optional parameters in the dynamic ...
Since Next 9.5 you can do it by using optional catch-all routes. You would have a route like this /[bookId]/[[...chapterId]] .
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