Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
fix: ensure we use route fork if used within page
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Oct 1, 2022
1 parent 25e22fe commit 21d872c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/nuxt/src/app/components/layout.ts
@@ -1,6 +1,7 @@
import { computed, defineComponent, h, nextTick, onMounted, Ref, Transition, unref, VNode } from 'vue'
import { computed, defineComponent, h, inject, nextTick, onMounted, Ref, Transition, unref, VNode } from 'vue'
import { _wrapIf } from './utils'
import { useRouter } from '#app'
import { RouteLocationNormalizedLoaded, useRoute as useVueRouterRoute } from 'vue-router'
import { useRoute } from '#app'
// @ts-ignore
import layouts from '#build/layouts'
// @ts-ignore
Expand Down Expand Up @@ -44,10 +45,10 @@ export default defineComponent({
}
},
setup (props, context) {
// Use router.currentRoute.value instead because this must be changed synchronized with route
const router = useRouter()
const route = computed(() => router.currentRoute.value)
const layout = computed(() => unref(props.name) ?? route.value.meta.layout as string ?? 'default')
// Need to ensure (if we are not a child of `<NuxtPage>`) that we use synchronous route (not deferred)
const injectedRoute = inject('_route') as RouteLocationNormalizedLoaded
const route = injectedRoute === useRoute() ? useVueRouterRoute() : injectedRoute
const layout = computed(() => unref(props.name) ?? route.meta.layout as string ?? 'default')

let vnode: VNode
let _layout: string | false
Expand All @@ -67,7 +68,7 @@ export default defineComponent({
console.warn(`Invalid layout \`${layout.value}\` selected.`)
}

const transitionProps = route.value.meta.layoutTransition ?? defaultLayoutTransition
const transitionProps = route.meta.layoutTransition ?? defaultLayoutTransition

// We avoid rendering layout transition if there is no layout to render
return _wrapIf(Transition, hasLayout && transitionProps, {
Expand Down

0 comments on commit 21d872c

Please sign in to comment.