Files
ipal-kit/src/modules/pages/localeFromPath.ts
T
Radosław SmolińskiandClaude Opus 5.5 166bf51e53 Lazy 404: createNotFoundPage({ load }) + renderNotFoundView, NotFoundLoader
Next puts a layout's not-found tree into the RSC payload of every page under it. The eager
createNotFoundPage({ blocks }) rendered the panel's 404 page there in every locale, so with
404 = homepage each page shipped the homepage twice (homepage HTML 195 -> 146 KB gzip).
With { load } only <NotFoundLoader> is in the payload; the content comes from the project's
server action (renderNotFoundView, locale checked against configured locales) when a 404 shows.
The eager variant is unchanged. Docs: pages.md, i18n.md, AGENT.md, PROGRAMISTA, ipal-setup, CHANGELOG.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-20 00:46:44 +02:00

9 lines
407 B
TypeScript

/**
* The locale from the first URL segment (`/en/...` → `en`), or `defaultLocale`
* when the segment isn't one of `locales` (single-locale site, unknown prefix).
*/
export function localeFromPath(pathname: string, locales: readonly string[], defaultLocale: string): string {
const segment = pathname.split('/').filter(Boolean)[0] ?? ''
return locales.includes(segment) ? segment : defaultLocale
}