SvelteKit: routing from other folders

Samuele
3 min readJul 26, 2021
Photo by Bogdan Karlenko on Unsplash

I am continuing to explore Svelte, SvelteKit and GitHub Pages. It’s pretty easy to create a blog and use mdsvex to process markdown files. But I think that the imposed folder structure is limiting.

In SvelteKit the blog pages must be in a blog folder (or post, or any other name). The post url will look something like:

blog.stranianelli.com/2021/2021-07-26-sveltekit-routing-from-other-folders

Instead I prefer a simpler url:

blog.stranianelli.com/sveltekit-routing-from-other-folders

Partly because I write a few posts, partly for personal taste. I know that it is not a widespread practice but mine sine qua non condition to switch from Jekyll to Svelte is the possibility of use the same url structure.

There is another important condition: I want to keep post images in the same folder with the .md file. I prefer to keep everything together, it makes my life easier when I write.

I had to search a bit, but combining various pieces and trying and trying again I managed to get something working.

Before starting a few links:

--

--

Samuele

I'm a hobby programmer, experimenting with Svelte, Javascript, Construct 3 and magic tools