mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 07:40:33 +00:00
fix(nuxt): support RouterView
props in NuxtPage
(#5272)
This commit is contained in:
parent
f71ef42d50
commit
eb12c7a845
@ -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' }
|
||||
|
Loading…
Reference in New Issue
Block a user