1- import { defineComponent , h , Suspense , Transition } from 'vue'
1+ import { defineComponent , h , inject , provide , Suspense , Transition } from 'vue'
22import { RouteLocationNormalizedLoaded , RouterView } from 'vue-router'
33
44import { generateRouteKey , RouterViewSlotProps , wrapInKeepAlive } from './utils'
55import { useNuxtApp } from '#app'
66import { _wrapIf } from '#app/components/utils'
77
8+ const isNestedKey = Symbol ( 'isNested' )
9+
810export default defineComponent ( {
911 name : 'NuxtPage' ,
1012 props : {
@@ -16,14 +18,22 @@ export default defineComponent({
1618 setup ( props ) {
1719 const nuxtApp = useNuxtApp ( )
1820
21+ const isNested = inject ( isNestedKey , false )
22+ provide ( isNestedKey , true )
23+
1924 return ( ) => {
2025 return h ( RouterView , { } , {
2126 default : ( routeProps : RouterViewSlotProps ) => routeProps . Component &&
2227 _wrapIf ( Transition , routeProps . route . meta . pageTransition ?? defaultPageTransition ,
23- wrapInKeepAlive ( routeProps . route . meta . keepalive , h ( Suspense , {
24- onPending : ( ) => nuxtApp . callHook ( 'page:start' , routeProps . Component ) ,
25- onResolve : ( ) => nuxtApp . callHook ( 'page:finish' , routeProps . Component )
26- } , { default : ( ) => h ( routeProps . Component , { key : generateRouteKey ( props . pageKey , routeProps ) } as { } ) } ) ) ) . default ( )
28+ wrapInKeepAlive ( routeProps . route . meta . keepalive ,
29+ isNested
30+ // Include route children in parent suspense
31+ ? h ( routeProps . Component , { key : generateRouteKey ( props . pageKey , routeProps ) } as { } )
32+ : h ( Suspense , {
33+ onPending : ( ) => nuxtApp . callHook ( 'page:start' , routeProps . Component ) ,
34+ onResolve : ( ) => nuxtApp . callHook ( 'page:finish' , routeProps . Component )
35+ } , { default : ( ) => h ( routeProps . Component , { key : generateRouteKey ( props . pageKey , routeProps ) } as { } ) } )
36+ ) ) . default ( )
2737 } )
2838 }
2939 }
0 commit comments