Skip to content

Commit

Permalink
fix: support layout from defined vue page in DDM
Browse files Browse the repository at this point in the history
  • Loading branch information
Atinux committed Jun 27, 2022
1 parent 0396252 commit 48fc30b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/runtime/plugins/documentDriven.ts
Expand Up @@ -14,10 +14,13 @@ export default defineNuxtPlugin((nuxt) => {
/**
* Finds a layout value from a cascade of objects.
*/
const findLayout = (page: ParsedContent, navigation: NavItem[], globals: Record<string, any>) => {
const findLayout = (to: RouteLocationNormalized, page: ParsedContent, navigation: NavItem[], globals: Record<string, any>) => {
// Page `layout` key has priority
if (page && page?.layout) { return page.layout }

// Resolve key from .vue page meta
if (to.matched.length && to.matched[0].meta?.layout) { return to.matched[0].meta.layout }

// Resolve key from navigation
if (navigation && page) {
const { navKeyFromPath } = useContentHelpers()
Expand Down Expand Up @@ -197,7 +200,7 @@ export default defineNuxtPlugin((nuxt) => {
}

// Find used layout
const layoutName = findLayout(_page, _navigation, _globals)
const layoutName = findLayout(to, _page, _navigation, _globals)

// Prefetch layout component
const layout = layouts[layoutName]
Expand Down

0 comments on commit 48fc30b

Please sign in to comment.