Skip to content

Commit

Permalink
feat(vite/inertia): support default layouts in resolvePageComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
innocenzi committed Aug 4, 2022
1 parent 6b34fd5 commit 799a071
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions vite-plugin-laravel/src/inertia.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
/**
* Resolves a page component.
*/
export async function resolvePageComponent(name: string, pages: Record<string, any>) {
export async function resolvePageComponent(name: string, pages: Record<string, any>, defaultLayout?: any) {
const path = Object.keys(pages)
.sort((a, b) => a.length - b.length)
.find((path) => path.endsWith(`${name.replaceAll('.', '/')}.vue`))

if (!path) {
throw new Error(`Page not found: ${name}`)
throw new Error(`Page component "${name}" could not be found.`)
}

return typeof pages[path] === 'function'
let component = typeof pages[path] === 'function'
? await pages[path]()
: pages[path]

component = component.default ?? component
component.layout ??= defaultLayout

return component
}

0 comments on commit 799a071

Please # to comment.