-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Remove fallthrough #4330
Remove fallthrough #4330
Conversation
🦋 Changeset detectedLatest commit: aa415d9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I am relying quite a lot on fallthrough routes in their current state. I don't want to get locked out of bug fixes while waiting for part two.. Is this a |
It won't get merged until part two is ready — working on that now |
@@ -323,11 +323,10 @@ A route can have multiple dynamic parameters, for example `src/routes/[category] | |||
It's possible for multiple routes to match a given path. For example each of these routes would match `/foo-abc`: | |||
|
|||
```bash | |||
src/routes/[...catchall].svelte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should you be allowed to have [...catchall].svelte
and [b].svelte
? It seems like [b].svelte
will never be called, so maybe this should throw an error during build
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They would both be allowed once we implement part 2 of this with route validators, right? (And that is going to happen immediately after this PR.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[...catchall]
is a rest parameter. regardless of part 2, it will match /things/b/will/not/match
. We could throw an error for [a].js
alongside [b].svelte
, but I think we can do that separately to avoid bloating this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed this was the section where we showed the priority order of routes (GitHub collapsed the context around this). It looks like [..catchall].svelte
is still last in the priority ordering. I wonder if we should show it last here as well for consistency?
Migrating away from fallthrough routes
If you ended up here because you previously used fallthrough routes and need to figure out how to migrate away from them, welcome.
If you were previously using
fallthrough
to render a 404 (i.e. you weren't actually falling through to a separate route), just return the 404 explicitly.If you were using it to validate route parameters (i.e. you had
[foo].svelte
and[bar].svelte
, andfoo
andbar
had different requirements, you should use parameter validators instead.If you need to vary which components are rendered based on some other condition (e.g. whether a piece of data exists in a database), then you can do this sort of thing:
#4291, part 1 of 2. This removes fallthrough routes but doesn't add parameter validators (that's part 2).
I have a hunch that we can simplify
client.js
further, but that can happen in a follow-upPlease don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0