From 6974a6fa56412794c932c6ad9bfe2cebcc3a7da3 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Sat, 13 Apr 2019 14:54:09 +0200 Subject: [PATCH] fix: push before creating Vue instance (#2713) Fix #2712 --- examples/lazy-loading-before-mount/app.js | 39 +++++++++++++++++++ examples/lazy-loading-before-mount/index.html | 8 ++++ src/util/resolve-components.js | 2 +- test/e2e/specs/lazy-loading-before-mount.js | 11 ++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 examples/lazy-loading-before-mount/app.js create mode 100644 examples/lazy-loading-before-mount/index.html create mode 100644 test/e2e/specs/lazy-loading-before-mount.js diff --git a/examples/lazy-loading-before-mount/app.js b/examples/lazy-loading-before-mount/app.js new file mode 100644 index 000000000..a588a10c5 --- /dev/null +++ b/examples/lazy-loading-before-mount/app.js @@ -0,0 +1,39 @@ +import Vue from 'vue' +import VueRouter from 'vue-router' + +Vue.use(VueRouter) + +const Home = { template: '
Home
' } +const Foo = () => + new Promise(resolve => { + setTimeout(() => + resolve({ + template: `
This is Foo
` + }) + , 10) + }) + +const router = new VueRouter({ + mode: 'history', + base: __dirname, + routes: [ + { path: '/', component: Home }, + // Just use them normally in the route config + { path: '/async', component: Foo } + ] +}) + +router.push('/async') + +document.getElementById('load-button').addEventListener('click', (event) => { + new Vue({ + router, + template: ` +
+

Async

+ +
+ ` + }).$mount('#app') + event.target.remove() +}) diff --git a/examples/lazy-loading-before-mount/index.html b/examples/lazy-loading-before-mount/index.html new file mode 100644 index 000000000..23a13d577 --- /dev/null +++ b/examples/lazy-loading-before-mount/index.html @@ -0,0 +1,8 @@ + + +← Examples index +
+ + + + diff --git a/src/util/resolve-components.js b/src/util/resolve-components.js index 3f7608cd5..c6a2927c1 100644 --- a/src/util/resolve-components.js +++ b/src/util/resolve-components.js @@ -30,7 +30,7 @@ export function resolveAsyncComponents (matched: Array): Function { match.components[key] = resolvedDef pending-- if (pending <= 0) { - next() + next(to) } }) diff --git a/test/e2e/specs/lazy-loading-before-mount.js b/test/e2e/specs/lazy-loading-before-mount.js new file mode 100644 index 000000000..444dff33b --- /dev/null +++ b/test/e2e/specs/lazy-loading-before-mount.js @@ -0,0 +1,11 @@ +module.exports = { + 'lazy loading before mount': function (browser) { + browser + .url('http://localhost:8080/lazy-loading-before-mount/') + // wait for the Foo component to be resolved + .click('#load-button') + .waitForElementVisible('.foo', 1000) + .assert.containsText('.view', 'This is Foo') + .end() + } +}