Dynamic Route Parameters Options
See original GitHub issueIs 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:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
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.
We can already take advantage of fallthrough by not returning in the
load
function, so non-matches would already turn into a 404.