fixed resolveRoute.ts

This commit is contained in:
2026-08-06 18:44:28 +02:00
parent e76692c9ba
commit f7d5e79d27
2 changed files with 19 additions and 7 deletions
+18 -6
View File
@@ -28,16 +28,28 @@ import { archiveFieldName } from './types.js';
locale: locale
});
// 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) {
const homepage = settings.homepage;
if (homepage && typeof homepage === 'object') {
return {
type: 'home',
doc: homepage
};
}
if (!homepage || typeof homepage !== 'object') {
return null;
}
const homepageId = homepage.id;
const doc = await payload.findByID({
id: homepageId,
collection: pagesSlug,
depth: 2,
locale: locale
});
return doc ? {
type: 'home',
doc: doc
} : null;
}
const [first, ...rest] = segments;
// Does the first segment name an archive page?
for (const collection of content?.collections ?? []){
File diff suppressed because one or more lines are too long