Use a fallback for valid client routes. If it also swallows missing pages or API navigations, route those requests explicitly and verify status, body and content type with direct requests.
If an SPA works from its home page but fails on refresh, test the direct URL before changing the router. On Cloudflare Workers, the asset layer can serve an SPA shell for a valid client route.
The same fallback can return that shell for a missing route or an API navigation. Decide which requests should reach the app before turning on a blanket fallback.
I tested those three paths locally. Both the valid route and a nonexistent route returned the same 200 HTML when I sent a navigation header. The API path served JSON for an ordinary request and HTML when I included the header.
Reproduce the direct request outside the app
Pick one client route that should open directly, one URL you know is invalid and one API path that should return JSON. Enter the valid link in a fresh browser tab as well as clicking to it from the homepage.
A working client-side transition does not prove the host can answer the URL on reload.
For diagnosis, send both request shapes to your test host. Use GET so you can check the body as well as the status.
curl -i https://example.com/api/ping
curl -i -H 'Sec-Fetch-Mode: navigate' https://example.com/api/ping
The navigation header is a way to exercise the documented routing branch. It does not reproduce everything about a real browser or crawler. Record the status, the content type and a small body marker for each path.
What the two local configurations returned
The first fixture used assets.not_found_handling: "single-page-application" and compatibility date 2026-10-07. A direct request carrying the navigation header received 200 with the same HTML shell for /pricing and /pricing/no-such-page.
With that header, /api/ping also returned the shell. Without it, the Worker returned JSON.
Cloudflare’s SPA routing documentation explains this navigation behavior for compatibility dates from April 1, 2025 or when the corresponding flag is enabled. Check your compatibility date, flags and Worker-first setting before copying a fix.

Cropped from Cloudflare’s Workers documentation on navigation requests, licensed under CC BY-SA 4.0.
In the second fixture, the Worker ran first. It sent /pricing to the root asset, answered /api/ping in code and delegated remaining requests to assets configured with 404-page. The valid route kept 200 HTML, the nonexistent pricing URL returned 404, and the API navigation returned JSON.

Local Wrangler · navigation requests shown. Observed November 13, 2026.
Give known routes and missing records different outcomes
For a few fixed public paths, a small route map or prerendered files can make the behavior easy to reason about. For dynamic paths, the route may need to look up whether the record exists. A missing record should return 404. An outage in the lookup service needs separate error handling.
A logged-in dashboard can use a broad shell fallback if its route and auth model support it.
If the API lives under /api/ and needs to return JSON on direct navigation, you can set assets.run_worker_first to ["/api/*"]. An array uses explicit route patterns and disables automatic navigation-header detection. With run_worker_first: true, the Worker runs first for every request.
I’d start with the API prefix when the other paths can use normal asset routing. After changing the setting, retest one JSON endpoint, one known deep link and a normal static asset. Cloudflare advanced routing
For static content, Workers supports a real 404-page asset response. A client-side “not found” heading on a 200 shell does not change the HTTP status.
Where a client-only site cannot return a status itself, Google’s JavaScript SEO guide describes alternative handling. Cloudflare custom 404 pages · Google JavaScript SEO
Save the three expected responses before release
For each of your three test URLs, write down the expected status, content type and body marker. Deploy the change to an authorized preview and repeat with a fresh browser navigation and a normal HTTP request.
The known page should render the correct content. The missing URL should reach your intended missing-page behavior, and the JSON endpoint should serve JSON in the contexts you support.
For a site built in Lovable, also check which runtime produced the deployed page. The Lovable SEO guide shows how to distinguish readable HTML, discovery files and the status of a missing record on a real route.
Sources & scope
Capabilities are based on these official sources. Recommendations are editorial judgments. Hands-on scope: Navigation-shaped and ordinary HTTP GET requests against local Wrangler 4.148.0 Workers fixtures, compatibility date 2026-10-07. No production edge or crawler delivery measured.
- Cloudflare Workers SPA routing ↗Checked Dec 3, 2026
- Cloudflare Workers static 404 pages ↗Checked Dec 3, 2026
- Google JavaScript SEO and soft 404s ↗Checked Dec 3, 2026
- Google HTTP status code handling ↗Checked Dec 3, 2026