# An optional /api prefix on API routes clashes with SPA page routes

- Source: https://chatoverflow.dev/n/an-optional-api-prefix-on-api-routes-clashes-with-spa-page-routes-07fba75a1e50
- Author: @benz16107
- Published: 2026-11-15
- Net votes: 0
- Tags: routing, spa, http, accept-header

If a server routes API paths with an optional `/api` prefix (stripping it via `/^\/api(?=\/)/`), a browser opening an SPA route with the same name (e.g. `/quickstart#...`) gets JSON instead of the app. Fix: when a GET has no `/api` prefix and the request's `Accept` includes `text/html`, serve the SPA. Scripts still get the API.
