Added module Links
This commit is contained in:
+45
-9
@@ -62,27 +62,63 @@ Site Settings → System Pages → **404 (Not Found)**. Edytor wybiera:
|
||||
- stronę główną (część klientów tak woli), **albo**
|
||||
- nic → projekt pokazuje wbudowany fallback z `not-found.tsx`.
|
||||
|
||||
Projekt (`app/(frontend)/[locale]/not-found.tsx`) — pełny przykład w
|
||||
`frontend/[locale]/not-found.tsx`:
|
||||
Projekt — `app/(frontend)/[locale]/not-found.tsx` (pełny plik):
|
||||
|
||||
```tsx
|
||||
import React from 'react'
|
||||
|
||||
import { RenderBlocks } from '@intecion/ipal-kit/rsc'
|
||||
import { LocaleView } from '@intecion/ipal-kit/client'
|
||||
|
||||
import { i18nConfig } from '@/i18n.config'
|
||||
import { blockRegistry } from '@/blocks/registry'
|
||||
import { getConfiguredLocales, getNotFoundPage } from '@/lib/content'
|
||||
|
||||
/**
|
||||
* 404 view. The editor picks which page plays the 404 role in
|
||||
* Site Settings → System Pages → "404 (Not Found)" — a dedicated page or the
|
||||
* homepage — or leaves it empty → the fallback below.
|
||||
*
|
||||
* not-found.tsx receives no params, and reading headers() here would turn the
|
||||
* SSG/ISR site dynamic ("Page changed from static to dynamic at runtime").
|
||||
* So: render the 404 page for EVERY locale on the server (DB reads only — stays
|
||||
* static) and let <LocaleView> pick the one from the URL (/en/... → en).
|
||||
* Next still answers HTTP 404.
|
||||
*/
|
||||
export default async function NotFound() {
|
||||
const locales = await getConfiguredLocales()
|
||||
const views = Object.fromEntries(await Promise.all(locales.map(async (locale) => {
|
||||
const page = await getNotFoundPage(locale) // null → brak przypisania
|
||||
return [locale, page?.layout?.length
|
||||
? <RenderBlocks blocks={page.layout} components={blockRegistry} enhanceProps={() => ({ locale })} />
|
||||
: null]
|
||||
})))
|
||||
|
||||
const views = Object.fromEntries(
|
||||
await Promise.all(
|
||||
locales.map(async (locale) => {
|
||||
const page = (await getNotFoundPage(locale)) as { layout?: unknown[] } | null
|
||||
const view = page?.layout?.length ? (
|
||||
<RenderBlocks
|
||||
blocks={page.layout as never}
|
||||
components={blockRegistry}
|
||||
enhanceProps={() => ({ locale })}
|
||||
/>
|
||||
) : null
|
||||
return [locale, view] as const
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
// No 404 page assigned in any locale (or DB unreachable during build):
|
||||
// the project's own minimal view — style it, keep it text-free or panel-driven.
|
||||
if (Object.values(views).every((v) => v === null)) {
|
||||
return (
|
||||
<main className="container py-24 text-center">
|
||||
<h1 className="text-6xl font-bold">404</h1>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
return <LocaleView views={views} defaultLocale={i18nConfig.defaultLocale} />
|
||||
}
|
||||
```
|
||||
|
||||
> **NIE czytaj `headers()` w `not-found.tsx`** (`LocaleView` od 1.7.13). `not-found.tsx` nie dostaje
|
||||
> **NIE czytaj `headers()` w `not-found.tsx`** (`LocaleView` od 1.8.2). `not-found.tsx` nie dostaje
|
||||
> `params`, ale `headers()` (np. `x-locale` z proxy) zamienia stronę SSG/ISR w
|
||||
> dynamiczną — Next 16 rzuca `Page changed from static to dynamic at runtime`
|
||||
> (AGENT.md §4.6). Dlatego serwer renderuje stronę 404 **dla każdego języka**
|
||||
|
||||
Reference in New Issue
Block a user