You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some users (e.g. me) may want to prerender all routes using start, and then deploy the static files. In these cases, a prerendered 404.html is important becuase there are no servers rendering it in runtime.
For example, Nuxt emits 404.html when using its generate or --prerender cli parameters
from nuxt doc
If you deploy your app to static hosting with the nuxi generate or nuxi build --prerender commands, then by default, Nuxt will render every page as a separate static HTML file.
TS start is kind of different, because there is a "fuzzy" 404 handler, but i think it is okay to fallback to "root" if user is using a "*static` nitro preset.
As for when to emit 404.html, I find all *-static (static, vercel-static, github-pages etc.) nitro presets all sets the static opt to true. So simply check server.static in TS start app config (after applying presets) should work.
BTW redirecting everything to / (like in #3144) is a bad idea in this case because if so, the index will flicker for a sec, and, why do I even prerender other routes if I do so?
Edit: Have read SPA Mode Enhancements #3394 carefully. Here are a few arguments that I think _shell.tsx cannot replace a 404.html ouput in this use case (no server, can only use redirect):
For netlify, things is kind of easy: just use /* /_shell.html 404. This takes advantage of netlify's shadowing system, by default it will match the real prerendered page, and if there are no matches, it will be redirected to _shell.html, which is a 404 page and returns 404 code
But for Vercel, which seems to always shadowing the html file (my tests failed becuase "redirects": [{ "source": "/(.*)", "destination": "/index.html", "statusCode": 200 }] just gives me 404 for all pages) comes two problems:
my prerenders are not used, user will have a slow showing page, and the SEO will be bad;
I CANNOT get a 404 status code for using "redirects": [{ "source": "/[^.]+", "destination": "/", "statusCode": 200 }] becuase if i use 404 in redirect then every route is 404.
This does not align with our mental model. We all expected that a static file server finds matched files to serve, and serve a special file when 404. Redirectly all routes to a html which acts as 404, relying on non-shdowing behaviour to match actual files just don't feel right.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Some users (e.g. me) may want to prerender all routes using start, and then deploy the static files. In these cases, a prerendered 404.html is important becuase there are no servers rendering it in runtime.
For example, Nuxt emits 404.html when using its
generate
or--prerender
cli parametersTS start is kind of different, because there is a "fuzzy" 404 handler, but i think it is okay to fallback to "root" if user is using a "*static` nitro preset.
As for when to emit 404.html, I find all
*-static
(static
,vercel-static
,github-pages
etc.) nitro presets all sets thestatic
opt to true. So simply checkserver.static
in TS start app config (after applying presets) should work.BTW redirecting everything to
/
(like in #3144) is a bad idea in this case because if so, the index will flicker for a sec, and, why do I even prerender other routes if I do so?Edit: Have read SPA Mode Enhancements #3394 carefully. Here are a few arguments that I think
_shell.tsx
cannot replace a 404.html ouput in this use case (no server, can only use redirect):/* /_shell.html 404
. This takes advantage of netlify's shadowing system, by default it will match the real prerendered page, and if there are no matches, it will be redirected to _shell.html, which is a 404 page and returns 404 code"redirects": [{ "source": "/(.*)", "destination": "/index.html", "statusCode": 200 }]
just gives me 404 for all pages) comes two problems:"redirects": [{ "source": "/[^.]+", "destination": "/", "statusCode": 200 }]
becuase if i use 404 in redirect then every route is 404.Beta Was this translation helpful? Give feedback.
All reactions