mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-16 21:58:19 +00:00
fix(nuxt): stop loading indicator if page keys are the same (#24931)
This commit is contained in:
parent
a62f2ba3e3
commit
fd812ef636
@ -41,6 +41,7 @@ export default defineComponent({
|
|||||||
const nuxtApp = useNuxtApp()
|
const nuxtApp = useNuxtApp()
|
||||||
const pageRef = ref()
|
const pageRef = ref()
|
||||||
const forkRoute = inject(PageRouteSymbol, null)
|
const forkRoute = inject(PageRouteSymbol, null)
|
||||||
|
let previousPageKey: string | undefined | false
|
||||||
|
|
||||||
expose({ pageRef })
|
expose({ pageRef })
|
||||||
|
|
||||||
@ -88,6 +89,10 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const key = generateRouteKey(routeProps, props.pageKey)
|
const key = generateRouteKey(routeProps, props.pageKey)
|
||||||
|
if (!nuxtApp.isHydrating && !hasChildrenRoutes(forkRoute, routeProps.route, routeProps.Component) && previousPageKey === key) {
|
||||||
|
nuxtApp.callHook('page:loading:end')
|
||||||
|
}
|
||||||
|
previousPageKey = key
|
||||||
|
|
||||||
const hasTransition = !!(props.transition ?? routeProps.route.meta.pageTransition ?? defaultPageTransition)
|
const hasTransition = !!(props.transition ?? routeProps.route.meta.pageTransition ?? defaultPageTransition)
|
||||||
const transitionProps = hasTransition && _mergeTransitionProps([
|
const transitionProps = hasTransition && _mergeTransitionProps([
|
||||||
@ -148,3 +153,10 @@ function haveParentRoutesRendered (fork: RouteLocationNormalizedLoaded | null, n
|
|||||||
(c, i) => c.components?.default !== fork.matched[i]?.components?.default) ||
|
(c, i) => c.components?.default !== fork.matched[i]?.components?.default) ||
|
||||||
(Component && generateRouteKey({ route: newRoute, Component }) !== generateRouteKey({ route: fork, Component }))
|
(Component && generateRouteKey({ route: newRoute, Component }) !== generateRouteKey({ route: fork, Component }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasChildrenRoutes (fork: RouteLocationNormalizedLoaded | null, newRoute: RouteLocationNormalizedLoaded, Component?: VNode) {
|
||||||
|
if (!fork) { return false }
|
||||||
|
|
||||||
|
const index = newRoute.matched.findIndex(m => m.components?.default === Component?.type)
|
||||||
|
return index < newRoute.matched.length -1
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user