Skip to content

Commit 33571e0

Browse files
committed
support returning Promise in async components
1 parent 2956aea commit 33571e0

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/history/base.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* @flow */
22

33
import type VueRouter from '../index'
4+
import { warn } from '../util/warn'
45
import { inBrowser } from '../util/dom'
56
import { runQueue } from '../util/async'
67
import { isSameRoute } from '../util/route'
@@ -142,10 +143,21 @@ function resolveAsyncComponents (matched: Array<RouteRecord>): Array<?Function>
142143
// we want to halt the navigation until the incoming component has been
143144
// resolved.
144145
if (typeof def === 'function' && !def.options) {
145-
return (route, redirect, next) => def(resolvedDef => {
146-
match.components[key] = resolvedDef
147-
next()
148-
})
146+
return (route, redirect, next) => {
147+
const resolve = resolvedDef => {
148+
match.components[key] = resolvedDef
149+
next()
150+
}
151+
152+
const reject = reason => {
153+
warn(false, `Failed to resolve async component ${key}: ${reason}`)
154+
}
155+
156+
const res = def(resolve, reject)
157+
if (res && typeof res.then === 'function') {
158+
res.then(resolve, reject)
159+
}
160+
}
149161
}
150162
})
151163
}

0 commit comments

Comments
 (0)