You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.3 KiB
Markdown
65 lines
2.3 KiB
Markdown
+++
|
|
title = "Add `_redirects` SPA fallback — create file and include in Trunk build via copy-file"
|
|
priority = 8
|
|
status = "done"
|
|
ticket_type = "task"
|
|
dependencies = []
|
|
+++
|
|
|
|
<context>
|
|
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 `<link data-trunk rel="copy-file"
|
|
href="_redirects"/>` 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.
|
|
</context>
|
|
|
|
<goal>
|
|
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 `<head>`, alongside the other `data-trunk` links:
|
|
|
|
```html
|
|
<link data-trunk rel="copy-file" href="_redirects"/>
|
|
```
|
|
|
|
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
|
|
```
|
|
</goal>
|
|
|
|
<constraints>
|
|
- 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.
|
|
</constraints>
|
|
|
|
<validation>
|
|
```sh
|
|
trunk build
|
|
ls dist/_redirects # must exist
|
|
cat dist/_redirects # must print: /* /index.html 200
|
|
```
|
|
</validation>
|
|
|
|
<domain>quotesdb/ui</domain>
|