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

Commit

Permalink
fix(nuxt): support RouterView props in NuxtPage (#5272)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Jun 3, 2022
1 parent f71ef42 commit eb12c7a
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions packages/nuxt/src/pages/runtime/page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineComponent, h, inject, provide, Suspense, Transition } from 'vue'
import { RouteLocationNormalizedLoaded, RouterView } from 'vue-router'
import { DefineComponent, defineComponent, h, inject, provide, Suspense, Transition } from 'vue'
import { RouteLocationNormalized, RouteLocationNormalizedLoaded, RouterView } from 'vue-router'

import { generateRouteKey, RouterViewSlotProps, wrapInKeepAlive } from './utils'
import { useNuxtApp } from '#app'
Expand All @@ -9,20 +9,27 @@ const isNestedKey = Symbol('isNested')

export default defineComponent({
name: 'NuxtPage',
inheritAttrs: false,
props: {
name: {
type: String
},
route: {
type: Object as () => RouteLocationNormalized
},
pageKey: {
type: [Function, String] as unknown as () => string | ((route: RouteLocationNormalizedLoaded) => string),
default: null
}
},
setup (props) {
setup (props, { attrs }) {
const nuxtApp = useNuxtApp()

const isNested = inject(isNestedKey, false)
provide(isNestedKey, true)

return () => {
return h(RouterView, {}, {
return h(RouterView, { name: props.name, route: props.route, ...attrs }, {
default: (routeProps: RouterViewSlotProps) => routeProps.Component &&
_wrapIf(Transition, routeProps.route.meta.pageTransition ?? defaultPageTransition,
wrapInKeepAlive(routeProps.route.meta.keepalive,
Expand All @@ -37,6 +44,11 @@ export default defineComponent({
})
}
}
})
}) as DefineComponent<{
name?: string,
route?: RouteLocationNormalized
pageKey?: string | ((route: RouteLocationNormalizedLoaded) => string)
[key: string]: any
}>

const defaultPageTransition = { name: 'page', mode: 'out-in' }

0 comments on commit eb12c7a

Please sign in to comment.