@@ -307,70 +307,65 @@ function poll (
307
307
}
308
308
309
309
function resolveAsyncComponents ( matched : Array < RouteRecord > ) : Function {
310
- let _next
311
- let pending = 0
312
- let error = null
313
-
314
- flatMapComponents ( matched , ( def , _ , match , key ) => {
315
- // if it's a function and doesn't have cid attached,
316
- // assume it's an async component resolve function.
317
- // we are not using Vue's default async resolving mechanism because
318
- // we want to halt the navigation until the incoming component has been
319
- // resolved.
320
- if ( typeof def === 'function' && def . cid === undefined ) {
321
- pending ++
322
-
323
- const resolve = once ( resolvedDef => {
324
- // save resolved on async factory in case it's used elsewhere
325
- def . resolved = typeof resolvedDef === 'function'
326
- ? resolvedDef
327
- : _Vue . extend ( resolvedDef )
328
- match . components [ key ] = resolvedDef
329
- pending --
330
- if ( pending <= 0 && _next ) {
331
- _next ( )
332
- }
333
- } )
310
+ return ( to , from , next ) => {
311
+ let hasAsync = false
312
+ let pending = 0
313
+ let error = null
314
+
315
+ flatMapComponents ( matched , ( def , _ , match , key ) => {
316
+ // if it's a function and doesn't have cid attached,
317
+ // assume it's an async component resolve function.
318
+ // we are not using Vue's default async resolving mechanism because
319
+ // we want to halt the navigation until the incoming component has been
320
+ // resolved.
321
+ if ( typeof def === 'function' && def . cid === undefined ) {
322
+ hasAsync = true
323
+ pending ++
324
+
325
+ const resolve = once ( resolvedDef => {
326
+ // save resolved on async factory in case it's used elsewhere
327
+ def . resolved = typeof resolvedDef === 'function'
328
+ ? resolvedDef
329
+ : _Vue . extend ( resolvedDef )
330
+ match . components [ key ] = resolvedDef
331
+ pending --
332
+ if ( pending <= 0 ) {
333
+ next ( )
334
+ }
335
+ } )
334
336
335
- const reject = once ( reason => {
336
- const msg = `Failed to resolve async component ${ key } : ${ reason } `
337
- process . env . NODE_ENV !== 'production' && warn ( false , msg )
338
- if ( ! error ) {
339
- error = reason instanceof Error
340
- ? reason
341
- : new Error ( msg )
342
- if ( _next ) _next ( error )
343
- }
344
- } )
337
+ const reject = once ( reason => {
338
+ const msg = `Failed to resolve async component ${ key } : ${ reason } `
339
+ process . env . NODE_ENV !== 'production' && warn ( false , msg )
340
+ if ( ! error ) {
341
+ error = reason instanceof Error
342
+ ? reason
343
+ : new Error ( msg )
344
+ next ( error )
345
+ }
346
+ } )
345
347
346
- let res
347
- try {
348
- res = def ( resolve , reject )
349
- } catch ( e ) {
350
- reject ( e )
351
- }
352
- if ( res ) {
353
- if ( typeof res . then === 'function' ) {
354
- res . then ( resolve , reject )
355
- } else {
356
- // new syntax in Vue 2.3
357
- const comp = res . component
358
- if ( comp && typeof comp . then === 'function' ) {
359
- comp . then ( resolve , reject )
348
+ let res
349
+ try {
350
+ res = def ( resolve , reject )
351
+ } catch ( e ) {
352
+ reject ( e )
353
+ }
354
+ if ( res ) {
355
+ if ( typeof res . then === 'function' ) {
356
+ res . then ( resolve , reject )
357
+ } else {
358
+ // new syntax in Vue 2.3
359
+ const comp = res . component
360
+ if ( comp && typeof comp . then === 'function' ) {
361
+ comp . then ( resolve , reject )
362
+ }
360
363
}
361
364
}
362
365
}
363
- }
364
- } )
366
+ } )
365
367
366
- return ( to , from , next ) = > {
367
- if ( error ) {
368
- next ( error )
369
- } else if ( pending <= 0 ) {
370
- next ( )
371
- } else {
372
- _next = next
373
- }
368
+ if ( ! hasAsync ) next ( )
374
369
}
375
370
}
376
371
0 commit comments