fix(nuxt): support RouterView props in NuxtPage (#5272)

This commit is contained in:
Daniel Roe 2022-06-03 16:01:46 +02:00 committed by GitHub
parent f71ef42d50
commit eb12c7a845
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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'
@ -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,
@ -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' }