fixed resolveRoute.ts
This commit is contained in:
Vendored
+18
-6
@@ -28,15 +28,27 @@ 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;
|
||||
}
|
||||
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?
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user