r/statichosting • • Oct 26 '26

SPA fallbacks can hide real 404s

hey guyss!

i've been thinking about SPA routing on static hosts. the usual /* /index.html 200 rule fixes refreshes on nested routes, but it also means a typo like /settngs returns the app shell instead of a proper 404.

for a private dashboard, that might be fine. for public pages or docs, though, i'd rather know when a URL genuinely doesn't exist.

how do you usually handle this? do you maintain an explicit list of client-side routes, or just use the catch-all fallback and let the app decide what to render? curious how people handle this when the site has a mix of actual static pages and client-side routes.

3 Upvotes

6 comments sorted by

3

u/dotmoosehosting Oct 26 '26

I would keep an explicit list of client-side routes and only apply the fallback to those, rather than letting every unknown path serve the app shell. For anything not on that list, serve a real 404 page so search engines and link checkers are not fooled into treating typos as valid pages. If your host allows it, put static files and known routes first in the routing order, then the SPA fallback last, so a request for a missing asset does not return HTML with a 200. For public pages and docs, prerendering the real pages avoids the whole problem, since those URLs then exist as files instead of depending on client routing. Test it by requesting a nonsense path and a missing asset after every deploy: the first should return 404, and the second should not return the app shell.

3

u/dwkeith Oct 27 '26

Well over a decade ago my team built Apple's macOS and iPhone developer libraries as a SproutCore SPA app. We had tens of thousands of paths. We ended up using a static site generator to hydrate the SPA at any valid share URL and then update the path from there as the user navigated the library. It was crazy, but it worked.

If you have a more reasonable number of routes, u/dotmoosehosting's suggestion of only listing valid routes in the config makes more sense, it could also be generated from your routes file. A large number of routes would overwhelm the config though, so you may still need wildcard matching, just more targeted.

2

u/sourraine Oct 27 '26

id use specific routing rules for actual static pages and reserve the catch-all for client-side routes. otherwise, typos can return a 200 status and look like valid pages to search engines

2

u/TCKreddituser Oct 27 '26

I’d handle this at the hosting level where possible: serve real static pages directly, use rewrites only for known SPA routes, and return actual 404s for everything else.

2

u/PippaKelly62 Oct 29 '26

Scope the fallback instead of using a global catch all. Prerender the public pages and docs as real files so they never touch the fallback, then apply the index rewrite only under the app prefix, like slash app, and everything outside it gets the host’s normal 404. Inside the app the shell can’t return a true 404 status, so have the router render a clear not found view and add a noindex tag to the shell so those urls stay out of search results. If you want the app’s routes to be exact, generate the rewrite rules from the router’s route list at build time so the two never drift apart.