+++
title = "Add `_redirects` SPA fallback — create file and include in Trunk build via copy-file"
priority = 8
status = "done"
ticket_type = "task"
dependencies = []
+++
Resolved from TRIAGE ticket e2bd9b. Yew uses client-side routing (BrowserRouter), so a direct
URL such as `/browse` or `/quotes/abc123` will 404 on Cloudflare Pages unless a fallback is
configured. The chosen approach is a `_redirects` file with `/* /index.html 200`, which instructs
Cloudflare Pages to serve `index.html` for any path that does not match a static asset — without
changing the URL in the browser (HTTP 200 proxy, not a redirect).
This file must be present in the `dist/` output directory that `wrangler pages deploy` uploads.
Trunk handles this via its `copy-file` asset type: adding a `` line to `index.html` causes Trunk to copy the file verbatim into `dist/`
on every build.
The API Worker claims `/api/*` at the Cloudflare routing level before Pages processes the request,
so the `/* /index.html 200` catch-all does not interfere with the API.
1. Create `_redirects` at the `quotesdb/` project root (next to `index.html`) containing exactly:
```
/* /index.html 200
```
2. Add the following line to `index.html` inside ``, alongside the other `data-trunk` links:
```html
```
3. Run `trunk build` and verify that `dist/_redirects` exists with the correct single-line content.
4. Commit with:
```
chore(quotesdb): add _redirects SPA fallback for Cloudflare Pages routing
```
- The `_redirects` file must live at the project root (same level as `index.html` and `Trunk.toml`),
not inside `src/` or a `static/` subdirectory.
- The line must use a 200 (proxy) code, not 301 or 302 — 200 preserves the URL in the browser,
which is required for client-side routing to work correctly.
- Do NOT add `/* /index.html 200` to the `_headers` file — headers do not fix routing.
- This ticket is scoped to file creation and Trunk build verification only. The CI/CD deploy
workflow is handled separately in ticket 5137d7.
```sh
trunk build
ls dist/_redirects # must exist
cat dist/_redirects # must print: /* /index.html 200
```
quotesdb/ui