Search code examples
sveltesveltekit

Custom 404 Error Pages in SvelteKit Not Rendering as Expected Based on Folder Structure


I'm building an application using SvelteKit and I want to create custom error pages that are specific to different parts of my application based on their folder structure. My understanding is that SvelteKit should allow me to have +error.svelte files in different folders, and any 404 errors encountered within those folders should trigger the nearest +error.svelte file.

However, this doesn't seem to be working as expected.

My current file structure looks like this:

+error.svelte
(app)/+page.svelte
(app)/+error.svelte
dashboard/+page.svelte
dashboard/+error.svelte

When I navigate to a non-existent page like dashboard/blbla, instead of rendering the +error.svelte inside the dashboard folder, it always falls back to the root +error.svelte file.

How can I configure SvelteKit to render the closest +error.svelte file within the relevant folder when a 404 error occurs? Is there something I'm missing in my setup?

I took a look at How to add a custom 404 page and a different Error page (for other errors) in SvelteKit?

But that does not work for me. Am i missing something?


Solution

  • I found an old issue suggesting you can achieve this using rest parameters.

    And they actually even explains this in the docs, if you manage to find it ^^'