Why does a SPA route return 404 after refresh?

Client routing may open a page that the server does not recognize at the same URL. Check that direct navigation and refresh return the expected HTML. Avoid turning genuinely nonexistent URLs into successful pages.

How to check it

  1. Open the URL directly in a new tab, not only through navigation.
  2. Inspect the HTTP status and returned HTML title.
  3. Test host routing alongside real assets, API paths and nonexistent routes.

Concrete example

Example: if /tr/news opens from a menu but disappears on refresh, inspect static route output and host fallback rules. Verify that an API endpoint does not receive index.html instead of JSON.

Avoid a false conclusion

Rewriting everything to index.html can hide broken links behind soft 404s. Distinguish known routes from unknown routes.

Reference

Official reference

VCT Editorial

All answers