Skip to content

Commit

Permalink
fix async component resolving with Webpack 2 require.ensure
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 26, 2017
1 parent 7459c53 commit dd9d362
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/history/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,20 @@ function resolveAsyncComponents (matched: Array<RouteRecord>): Array<?Function>
// resolved.
if (typeof def === 'function' && !def.options) {
return (to, from, next) => {
// in Webpack 2, require.ensure now also returns a Promise
// so the resolve/reject functions may get called an extra time
let called = false

const resolve = resolvedDef => {
if (called) return
called = true
match.components[key] = resolvedDef
next()
}

const reject = reason => {
if (called) return
called = true
warn(false, `Failed to resolve async component ${key}: ${reason}`)
next(false)
}
Expand Down

0 comments on commit dd9d362

Please sign in to comment.