-
-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vite-plugin-kit-routes
generates incorrect routes when there could be multiple matches
#665
Comments
Thanks @Evertt for reporting this issue! I'm not sure we should move the optional route parameter to a non-optional one, as that might complicate things further. Instead, what about ensuring that there are no multiple properties with the same name? We could generate unique keys like /blog, /blog_alternative_2, /blog_alternative_3, etc. What do you think? |
Oh please no. 😅 How about that in the case that you have both a route So this: const PAGES = {
"/blog": `/blog`,
"/blog": (params?: {
id?: Parameters<typeof import("../params/integer.ts").match>[0]
}) => {
return `/blog${params?.id ? `/${params?.id}` : ""}`
},
} Turns into this: const PAGES = {
"/blog": (params?: {
id?: Parameters<typeof import("../params/integer.ts").match>[0]
}) => {
return `/blog${params?.id ? `/${params?.id}` : ""}`
},
} |
That's sounds great ! Thx for the proposal. I'll look at it tonight 🥳 (unless you wanna do it, comment here next few hours) |
Hey, that's interesting. So I just created a repro on stackblitz and what's interesting is that initially I got the same error from SvelteKit as you. But then when I made the routes folder resemble the one I had more accurately then suddenly SvelteKit's error disappeared. https://stackblitz.com/edit/sveltejs-kit-routing-bug-repro Which leads me to believe that maybe SvelteKit is actually supposed to throw the same error again, and that it's in fact a bug on their side that they don't throw the error in every case that they should? editTo make clear what changes I made to make SvelteKit's error go away:
I'm not sure which of those changes did the trick, but my guess is the first one. |
Looking at it quickly, it seems that the I'll try to do the repro also in #668 (but not right now ;)) |
You have any update here? |
Feel free to re open if you have news 😉 |
Describe the bug
So, let's say I have these weird routes:
As you can see, it's ambiguous where
/blog
would route to. It could route toroutes/(marketing)/blog/+page.svelte
or it could route toroutes/(marketing)/blog/(posts)/[[id=integer]]/+page.svelte
.According to the SvelteKit docs, when multiple matches are possible, SvelteKit will apply a sorting logic to decide which route to actually match with. In this case,
/blog
goes toroutes/(marketing)/blog/+page.svelte
.Anyway, what the plugin generates, is this:
Which of course throws this error:
But of course, what it should have done is to pretend that
id
is not an optional route parameter. Because then it would've generated this:Severity
annoyance
Steps to Reproduce the Bug
Create some route structure that creates ambiguity / multiple possible matches and see what the plugin generates.
Reproduction
No response
The text was updated successfully, but these errors were encountered: