mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-01 18:07:22 +00:00
fix(nuxt): extract component to provide route (#6325)
This commit is contained in:
parent
d1cc5cca69
commit
f75d0dfd47
@ -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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user