Don't know about you, but I've been hearing about this new routing system in SvelteKit. I first heard about this with the +error.svelte
file that I found here on the official docs. Not soon enough, I've also seen the other files like the __layout.svelte
file having a +
sign in front of it's filename like this: +layout.svelte
on the docs.
So I've been wondering:
npm install @sveltejs/kit@1.0.0-next.405
npx svelte-migrate routes
Running this command and hitting y
should result to this:
Done!
The following is optional for read.
I found some good material to come up with the solution above:
Quoting Rich Harris from this page:
New versions of SvelteKit include a design overhaul that will require some changes to your app.
To begin migrating your app, run the following command:
npx svelte-migrate routes
You will need to do this before installing the new version! We recommend updating to the most recent version before these changes —
@sveltejs/kit@next.405
— and ensuring that your app works with that version before running the migration.This will rename files inside your routes folder (see this comment to learn more about the changes), migrate some of the changes automatically and annotate your code with errors that link back to this page and tell you what needs to be manually updated. You can find these errors by searching your codebase for
@migration
.
One of the most important reasons I've read is this one, again quoting Rich Harris:
There are multiple ways to express a route.
src/routes/foo.svelte
andsrc/routes/foo/index.svelte
are equivalent, and having two ways to do things is always a source of confusion. Each has downsides — too manyindex.svelte
files open in your editor gets confusing, butfoo.svelte
makes it awkward to colocate related files. I frequently find myself movingfoo.svelte
tofoo/index.svelte
as the route becomes more complex (e.g. it needs a dedicated error page, or it gains a child route, or I need to break something out into a separate component, or it needs a page endpoint, and so on). These changes are costly and annoying, and I always kick myself for not just always using folders.
You may read all the other good reasons on this link.