fix(nuxt): extract component to provide route (#6325)

This commit is contained in:
Daniel Roe 2022-08-03 11:38:46 +01:00 committed by GitHub
parent d1cc5cca69
commit f75d0dfd47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,23 +33,14 @@ export default defineComponent({
default: (routeProps: RouterViewSlotProps) => { default: (routeProps: RouterViewSlotProps) => {
if (!routeProps.Component) { return } if (!routeProps.Component) { return }
const Component = defineComponent({
setup () {
provide('_route', routeProps.route)
return () => h(routeProps.Component, {
key: generateRouteKey(props.pageKey, routeProps)
} as {})
}
})
return _wrapIf(Transition, routeProps.route.meta.pageTransition ?? defaultPageTransition, return _wrapIf(Transition, routeProps.route.meta.pageTransition ?? defaultPageTransition,
wrapInKeepAlive(routeProps.route.meta.keepalive, isNested && nuxtApp.isHydrating wrapInKeepAlive(routeProps.route.meta.keepalive, isNested && nuxtApp.isHydrating
// Include route children in parent suspense // Include route children in parent suspense
? h(Component) ? h(Component, { key: generateRouteKey(props.pageKey, routeProps), routeProps } as {})
: h(Suspense, { : h(Suspense, {
onPending: () => nuxtApp.callHook('page:start', routeProps.Component), onPending: () => nuxtApp.callHook('page:start', routeProps.Component),
onResolve: () => nuxtApp.callHook('page:finish', routeProps.Component) onResolve: () => nuxtApp.callHook('page:finish', routeProps.Component)
}, { default: () => h(Component) }) }, { default: () => h(Component, { key: generateRouteKey(props.pageKey, routeProps), routeProps } as {}) })
)).default() )).default()
} }
}) })
@ -63,3 +54,11 @@ export default defineComponent({
}> }>
const defaultPageTransition = { name: 'page', mode: 'out-in' } const defaultPageTransition = { name: 'page', mode: 'out-in' }
const Component = defineComponent({
props: ['routeProps'],
setup (props) {
provide('_route', props.routeProps.route)
return () => h(props.routeProps.Component)
}
})