defineComponent,
onErrorCaptured,
inject,
+ shallowRef,
} from 'vue'
+import {
+ NavigationGuardReturn,
+ RouteLocationNormalizedLoaded,
+} from '../../src/types'
// override existing style on dev with shorter times
if (!__CI__) {
</transition>
</router-view>
-
</div>
`,
console.log(`done at ${depth}!`)
if (depth > 1) {
- throw new Error('oops')
+ // throw new Error('oops')
}
return { suspenseProps }
function createSuspenseProps(name: string) {
function onPending() {
console.log('onPending:' + name)
+ console.log('Now remaining', ++remainingValidations)
}
function onResolve() {
console.log('onResolve:' + name)
+ if (resolveSuspense) {
+ resolveSuspense()
+ }
}
function onFallback() {
console.log('onFallback:' + name)
return { onPending, onResolve, onFallback }
}
+let resolveSuspense:
+ | ((value?: NavigationGuardReturn) => void)
+ | undefined
+ | null
+let rejectSuspense: ((reason: any) => void) | undefined | null
+let pendingRoute = shallowRef<
+ RouteLocationNormalizedLoaded | undefined | null
+>()
+let remainingValidations = 0
+
+router.beforeResolve((to, from) => {
+ return new Promise((resolve, reject) => {
+ // we need at least one, we increment the rest with onPending
+ // should probably be provided and then injected in each routerview to increment the counter
+ // then the resolve could decrement and check if it's under 0
+ remainingValidations = 1
+ if (resolveSuspense) {
+ resolveSuspense(false)
+ }
+ pendingRoute.value = to
+ resolveSuspense = () => {
+ if (--remainingValidations < 1) {
+ pendingRoute.value = null
+ resolveSuspense = null
+ resolve()
+ }
+ }
+ rejectSuspense = reason => {
+ pendingRoute.value = null
+ rejectSuspense = null
+ reject(reason)
+ }
+
+ console.log('pendingRoute set')
+ })
+})
+
const app = createApp({
setup() {
const route = useRoute()
onErrorCaptured((err, target, info) => {
console.log('caught at Root', err, target, info)
+ if (rejectSuspense) {
+ rejectSuspense(err)
+ }
// stop propagation
return false
})
return {
nextId,
suspenseProps,
+ pendingRoute,
}
},
<li><router-link :to="{ name: 'id2', params: { id: nextId }}" v-slot="{ route }">{{ route.fullPath }}</router-link></li>
</ul>
- <router-view v-slot="{ Component }">
+ <pre v-if="pendingRoute">Loading {{ pendingRoute.fullPath }} from {{ $route.fullPath }}</pre>
+
+ <router-view v-slot="{ Component }" :route="pendingRoute">
<transition name="fade" mode="out-in" v-if="Component">
<suspense :timeout="0" v-bind="suspenseProps">
<component :is="Component" />
</transition>
</router-view>
+
</div>
`,
})