How a request is served
An app declares its locales, its preferences and its flags once, in
lib/indicators.ts.
Everything else follows from that declaration: the
rewrites in next.config.ts, the params of the static build, the links, and
what a layout reads.
What a request goes through
Take GET /login with a theme~dark cookie, from a browser in New York.
- The proxy matches only the site root, so it does not run.
- Redirects.
/loginis already canonical./en/loginwould have been sent to/login, since the default locale stays out of public URLs. - Rewrites. In
beforeFiles, one small step at a time, the path becomes/en/theme~dark/tz~EST/login: the default locale, then two empty segments, then each matching cookie or header appends its pair. See Rewrites. - The route.
app/[locale]/[prefs]/[flags]/login/page.tsxrenders, or rather was rendered at build time, becausegenerateStaticParamslisted this combination. The browser's URL is still/login.
The layout reads locale, prefs and flags from its params — not from
cookies or headers, which would make it dynamic — and renders
<html lang="en" data-theme="dark">.
The three segments
/[locale]/[prefs]/[flags]/...route
| Segment | Holds | Comes from | Example |
|---|---|---|---|
[locale] | one locale | the URL, or negotiation at the root | fr-CA |
[prefs] | choices the user made | cookies | theme~dark.tz~EST |
[flags] | facts about the request | headers | lang~fr.tz~EST |
A segment with nothing in it is -. The pairs in a segment are sorted by
key, which is what makes the path a stable cache key — see
Paths.
A tree need not have all three. segments: ['locale'] gives
app/[locale]/…, for a site whose pages are too heavy to copy per
preference; its preferences are then expressed through
stylesheets instead. A site in one language leaves
locales out too, and segments: [] is a plain app/….
What the app has to do
- Declare the indicators with
createIndicators. - Wrap
next.config.tswithwithFairGardenIndicators, from its own entry point. - Put its routes under
app/[locale]/[prefs]/[flags]/, and exportgenerateStaticParamsfrom the layout. - Read the params with
reador the layout wrappers, nevercookies()orheaders(). - Link with the
LinkfromcreateNavigation, so hrefs carry the locale. - Ship a
proxy.tsfromcreateLocaleProxyif visitors arrive at the root without a locale.
What runs, and what does not
Every step above is routing: beforeFiles rewrites, redirects and
headers in next.config.ts, which the routing layer applies before any
page code, plus static files in public/. So a page's variant is decided
with:
- No inline script. The theme is
data-themein the HTML the browser receives andcolor-schemein a stylesheet it loads before painting. A script is never in the path to the first frame, so there is no frame in the wrong state. A script would also see less than the routing layer does. A header added on the way to the server never reaches the browser; the country an edge network works out from the IP is an example. AnHttpOnlycookie is hidden from scripts. A rewrite can match on either, and the page only ever sees the name of the value that matched. - No serverless function. Every variant is prerendered, or rendered once on its first request and static from then on. A stylesheet preference is a static file the request is rewritten to. A hard flag's page is a static page in another directory.
- No middleware, with one exception: the proxy that negotiates the
locale at the site root, matched on
/and nothing else. A site in one language has no proxy at all. The Pages Router'si18nconfig did this in the routing layer —localeDetectionredirected the root byAccept-Language, and aNEXT_LOCALEcookie overrode it, the same two inputs in the same order — but the App Router does not support it, and that is the proxy's only reason to exist. Nothing here stands in the way of it coming back; if it does, the proxy goes and the rest is unchanged.
Scripts do run after the page. usePref writes a cookie and refreshes, or
fetches a stylesheet again, and what comes back is served the same way the
page was.
What it does not do
It does not translate anything. The locale is a segment and a param; what an app does with it is its own business.
It does not read a cookie or header at render time, and nothing here calls
cookies() or headers(). If a page needs a value that is not in the path,
that value is not an indicator yet — declare it, and it becomes one.