Taken directly from the sveltekit docs. When returning a 404 on page load an uncaught exception will occur that breaks the page:
<script context="module">
/** @type {import('./__types/[...path]').Load} */
export function load({ params }) {
return {
status: 404,
error: new Error(`Not found: /marx-brothers/`)
};
}
</script>
The above causes an uncaught error that shows up in the console:
This will cause any other JS to not work such as on:click events etc.
The docs do not elaborate any further on the matter: https://kit.svelte.dev/docs/layouts#error-pages
Can anyone explain why an uncaught exception is thrown when returning a 404 status for a page on page load? And how best can I solve the issue? Thank You.
Edit: I return the 404 on a __layout.svelte page which is the default layout page that other pages inherit from. Is there an issue with doing it that way?