{"success":true,"name":"every-spa-url-must-survive-refresh-and-direct-visits-configu","description":"The app works when clicked through, but refreshing an inner page gives 404","category":"ai-brimind","path":"ai-brimind/every-spa-url-must-survive-refresh-and-direct-visits-configu/SKILL.md","file":"SKILL.md","content":"---\nname: every-spa-url-must-survive-refresh-and-direct-visits-configu\ndescription: \"The app works when clicked through, but refreshing an inner page gives 404\"\n---\n\n# Every SPA URL Must Survive Refresh and Direct Visits: Configure the Server Rewrite\n\n## When to use\nA single-page app handles routing in the browser, and visiting or refreshing any deep URL returns the server's 404 — or deep links can't be shared.\n\n## Example request\nF5 on /players/42 → the server looks for that file, finds nothing; unrewritten route. shared link to an inner page → recipient lands on 404; broken deep link. works in dev, 404s in production → the dev server rewrote silently, the real host doesn't; missing prod config. — each forgot the server never heard of the router.\n\n## Instructions\nAct as a receptionist who forwards every unknown visitor to the main desk instead of turning them away — the main desk (your app) knows where everyone goes. Client-side routing exists only after the app loads: the server receiving a request for a deep path has no idea that path is 'a route', so unless configured, it honestly answers 404. The fix is a rewrite rule on the serving layer: any path that doesn't match a real file or API route serves the app's entry HTML, letting the router take over — each host has its own syntax (redirect rules, fallback settings, try-files directives); apply the one for your actual production host, because the dev server doing this automatically is exactly why the bug hides until deploy. Scope the rule correctly: API paths and real static assets must NOT be rewritten, or missing files return HTML disguised as scripts — the confusing 'unexpected token <' error. Have the router show its own not-found screen, since the server now never 404s for pages. Frameworks with server-side routing handle this natively — this applies to purely client-rendered apps. Test in the production setup: refresh the deepest route, paste it into a fresh tab, and request a genuinely missing asset to confirm it still 404s. Only proceed once every URL in the app is a working front door, not just an internal hallway.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #785\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}