Commit 25fe25b5 authored by Jimmy Lai's avatar Jimmy Lai

Document output export fallback host rewrites

parent 3f821ad3
...@@ -248,7 +248,7 @@ For example, `/docs/[section]/[page]` is matched before `/docs/[...slug]`, so `/ ...@@ -248,7 +248,7 @@ For example, `/docs/[section]/[page]` is matched before `/docs/[...slug]`, so `/
#### Static host configuration #### Static host configuration
To serve unenumerated params on a static host, configure the host's 404 or error document to serve `_fallback.html` from the export output: To serve unenumerated params on a static host, configure the host's 404 or error document to serve `_fallback.html` from the export output for document navigations:
| Host | Configuration | | Host | Configuration |
| --------------- | -------------------------------------------------- | | --------------- | -------------------------------------------------- |
...@@ -259,6 +259,22 @@ To serve unenumerated params on a static host, configure the host's 404 or error ...@@ -259,6 +259,22 @@ To serve unenumerated params on a static host, configure the host's 404 or error
When a user visits an unenumerated route, the host serves `_fallback.html`. The Next.js client router then discovers the correct fallback shell and renders the page with param-dependent content loading on the client. When a user visits an unenumerated route, the host serves `_fallback.html`. The Next.js client router then discovers the correct fallback shell and renders the page with param-dependent content loading on the client.
When your host supports it, prefer rewriting only document navigations to `_fallback.html`. Internal Next.js data requests such as missing `*.txt` and `*.json` fallback artifacts should stay normal 404s instead of being rewritten to HTML. This keeps the critical path shorter and avoids turning an internal probe into an extra HTML response.
For example, on Nginx you can preserve 404s for missing data assets while still rewriting document navigations:
```nginx filename="nginx.conf"
location ~ \.(txt|json)$ {
try_files $uri =404;
}
location / {
try_files $uri $uri.html $uri/ /_fallback.html;
}
```
If your host can only apply one broad catch-all rewrite, `/_fallback.html` will still work, but missing internal data requests may also be rewritten to HTML. The page will still recover, but you may see extra fallback probes in the network waterfall.
For client-side navigations (clicking a `<Link>`), the fallback shell is prefetched during hover, so navigation is instant. For client-side navigations (clicking a `<Link>`), the fallback shell is prefetched during hover, so navigation is instant.
For example, with App Router dynamic routes, `output: 'export'`, and `cacheComponents: true`, an Nginx config can serve both prerendered files and unknown params like this: For example, with App Router dynamic routes, `output: 'export'`, and `cacheComponents: true`, an Nginx config can serve both prerendered files and unknown params like this:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment