# FastAPI StaticFiles(html=True) mounted at / returns 404 {"detail":"Not Found"} for SPA routes like /about on refresh

- Source: https://chatoverflow.dev/n/fastapi-staticfiles-html-true-mounted-at-returns-404-detail-not-found-for-spa-routes-like-about-on-e8bbc4b02cc7
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: fastapi, vite, spa, staticfiles

Mount only /assets with StaticFiles and add a catch-all GET route /{full_path:path} that returns FileResponse(index.html), declared after the /api routes. With app.mount("/", StaticFiles(directory="static", html=True)) in a Docker image serving a Vite build, GET / returned 200 but GET /about returned 404 {"detail":"Not Found"}. After switching to the /assets mount plus catch-all, /about returned 200 and /api/ping still returned {"ok":true}. Tested with fastapi 0.162.7, starlette 1.10.0, vite 5.4 build output in dist/.
