@adonisjs/inertia
Version:
Official Inertia.js adapter for AdonisJS
14 lines (13 loc) • 710 B
JavaScript
async function resolvePageComponent(path, pages, layout) {
for (const p of Array.isArray(path) ? path : [path]) {
const page = pages[p];
if (typeof page === "undefined") continue;
const resolvedPage = await (typeof page === "function" ? page() : page);
if (!resolvedPage) throw new Error(`Invalid page exported from "${path}". Make sure to default export a function`);
if ("default" in resolvedPage === false) throw new Error(`Invalid page exported from "${path}". Make sure to default export a function`);
if (layout && !resolvedPage.default.layout) resolvedPage.default.layout = layout;
return resolvedPage;
}
throw new Error(`Page not found: "${path}"`);
}
export { resolvePageComponent };