fixed resolveRoute.ts

This commit is contained in:
2026-08-05 16:38:25 +02:00
parent 90cbc4370f
commit e76692c9ba
+17 -3
View File
@@ -82,14 +82,28 @@ export async function resolveRoute({
})) as Record<string, unknown> })) as Record<string, unknown>
// Locale root → Homepage from System Pages. // Locale root → Homepage from System Pages.
// settings.homepage is a shallow relation (depth: 1 above) — it identifies
// WHICH page is the homepage, but its nested block relations (e.g. Hero
// images) aren't populated. Re-fetch that page from the pages collection at
// the same depth as every other page, so the frontend gets one consistent
// shape. Uses pagesSlug/locale from args — no hard-coded collection or locale.
if (!segments?.length) { if (!segments?.length) {
const homepage = settings.homepage const homepage = settings.homepage
if (homepage && typeof homepage === 'object') { if (!homepage || typeof homepage !== 'object') {
return { type: 'home', doc: homepage as Record<string, unknown> }
}
return null return null
} }
const homepageId = (homepage as { id: number | string }).id
const doc = await payload.findByID({
id: homepageId,
collection: pagesSlug,
depth: 2,
locale: locale as never,
})
return doc ? { type: 'home', doc: doc as Record<string, unknown> } : null
}
const [first, ...rest] = segments const [first, ...rest] = segments
// Does the first segment name an archive page? // Does the first segment name an archive page?