Add a straightforward way to export error pages with `adapter-static`
See original GitHub issueIs your feature request related to a problem? Please describe.
There doesn’t seem to be a proper way to export a 404 for static sites. In Sapper, adding /404
as a second entry point would export an additional /404/index.html
; in SvelteKit, there is currently no similar option.
Related to #1172, but with the specific goal of handling non-SPA exports.
Describe the solution you’d like
Assuming this has no value outside of static export, it probably should be a separate option for adapter-static
. Error routes should not be required to explicitly exist and should be exempt from the default ‘fail on error’ policy.
(A nice touch would be the ability to trigger specific errors from here, e.g. by passing error codes for prerendering. This way, websites that need more than a simple 404 (e.g. sites operating within larger systems may also want 502 and 504) could be catered for. I wonder, however, if this is common enough to mind.)
Describe alternatives you’ve considered In theory, offering a way to force prerendering no matter the status code would allow simply adding separate entries in the config, effectively replicating Sapper’s behaviour. This would be undesirable, as I believe SvelteKit’s ‘all errors are build errors’ behaviour is excellent and should remain otherwise intact.
A workaround currently requires error routes to exist as normal pages. This works, but leads to some duplication between $error.svelte
and 404.svelte
, is not very portable (a 404.svelte
that in fact returns 200
makes no sense with, say, adapter-node
), and generally ticks all boxes to qualify as a hack.
How important is this feature to you? A 404 page is important in static export, and relying on hacks in performing such a common task shouldn’t be necessary.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:10
- Comments:10 (5 by maintainers)
Top GitHub Comments
What I’m doing now is
src/routes/404.svelte
– which builds to/build/404/index.html
(currently using static adapter).So then I add a
postbuild
npm script to move that file to the correct location:Oh, right, thanks, I missed this one. An option would be nice indeed.
However, the resulting fallback doesn’t render a 404 using
$error.svelte
, it simply renders a blank page withspa: true
, which ultimately solves a different problem.What am I still missing?