From ec6eab77707f5bb85282907b4c0656a670c3ed36 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 17 Apr 2019 10:42:37 +0200 Subject: [PATCH] fix: revert #2713 (#2723) Closes #2719 --- examples/basic/app.js | 16 +++++++++++++++- examples/lazy-loading-before-mount/app.js | 4 +++- examples/lazy-loading/app.js | 13 +++++++++++++ src/util/resolve-components.js | 2 +- test/e2e/specs/basic.js | 9 +++++++++ test/e2e/specs/lazy-loading.js | 14 +++++++++++++- 6 files changed, 54 insertions(+), 4 deletions(-) diff --git a/examples/basic/app.js b/examples/basic/app.js index 3140f03ce..e1ae4dede 100644 --- a/examples/basic/app.js +++ b/examples/basic/app.js @@ -29,6 +29,7 @@ const router = new VueRouter({ // Route components will be rendered inside . new Vue({ router, + data: () => ({ n: 0 }), template: `

Basic

@@ -43,9 +44,22 @@ new Vue({
  • /é?t=%ñ
  • /é#%25ñ
  • + +
    {{ n }}
    {{ $route.query.t }}
    {{ $route.hash }}
    - ` + `, + + methods: { + navigateAndIncrement () { + const increment = () => this.n++ + if (this.$route.path === '/') { + this.$router.push('/foo', increment) + } else { + this.$router.push('/', increment) + } + } + } }).$mount('#app') diff --git a/examples/lazy-loading-before-mount/app.js b/examples/lazy-loading-before-mount/app.js index a588a10c5..92be02792 100644 --- a/examples/lazy-loading-before-mount/app.js +++ b/examples/lazy-loading-before-mount/app.js @@ -23,7 +23,9 @@ const router = new VueRouter({ ] }) -router.push('/async') +router.onReady(() => { + router.push('/async') +}) document.getElementById('load-button').addEventListener('click', (event) => { new Vue({ diff --git a/examples/lazy-loading/app.js b/examples/lazy-loading/app.js index 95a057ce5..b62a288c2 100644 --- a/examples/lazy-loading/app.js +++ b/examples/lazy-loading/app.js @@ -43,6 +43,18 @@ const router = new VueRouter({ { path: '/', component: Home }, // Just use them normally in the route config { path: '/foo', component: Foo }, + // mulitple parameters, `/` should not be encoded. The name is also important + // https://github.com/vuejs/vue-router/issues/2719 + { path: '/a/:tags*', name: 'tagged', component: () => new Promise(resolve => { + setTimeout(() => { + resolve({ + template: `
    +

    Lazy with params

    +
    {{ $route.path }}
    +
    ` + }) + }, 200) + }) }, // Bar and Baz belong to the same root route // and grouped in the same async chunk. { path: '/bar', component: Bar, @@ -63,6 +75,7 @@ new Vue({
  • /foo
  • /bar
  • /bar/baz
  • +
  • /a/b/c
  • diff --git a/src/util/resolve-components.js b/src/util/resolve-components.js index c6a2927c1..3f7608cd5 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(to) + next() } }) diff --git a/test/e2e/specs/basic.js b/test/e2e/specs/basic.js index ad2e5c00f..850d8a049 100644 --- a/test/e2e/specs/basic.js +++ b/test/e2e/specs/basic.js @@ -40,6 +40,15 @@ module.exports = { .url('http://localhost:8080/basic/%C3%A9') .waitForElementVisible('#app', 1000) .assert.containsText('.view', 'unicode') + + // regression onComplete + // https://github.com/vuejs/vue-router/issues/2721 + .assert.containsText('#counter', '0') + .click('#navigate-btn') + .assert.containsText('#counter', '1') + .click('#navigate-btn') + .assert.containsText('#counter', '2') + .end() } } diff --git a/test/e2e/specs/lazy-loading.js b/test/e2e/specs/lazy-loading.js index 09993679c..8fdb788c9 100644 --- a/test/e2e/specs/lazy-loading.js +++ b/test/e2e/specs/lazy-loading.js @@ -3,7 +3,7 @@ module.exports = { browser .url('http://localhost:8080/lazy-loading/') .waitForElementVisible('#app', 1000) - .assert.count('li a', 4) + .assert.count('li a', 5) .assert.containsText('.view', 'home') .click('li:nth-child(2) a') @@ -28,6 +28,18 @@ module.exports = { .waitForElementVisible('#app', 1000) .assert.containsText('.view', 'This is Bar!') .assert.containsText('.view h3', 'Baz') + + // lazy loading with dynamic params: https://github.com/vuejs/vue-router/issues/2719 + // direct visit + .url('http://localhost:8080/lazy-loading/a/b/c') + .waitForElementVisible('#app', 1000) + .assert.containsText('.view', '/a/b/c') + // coming from another url + .url('http://localhost:8080/lazy-loading/') + .waitForElementVisible('#app', 1000) + .click('li:nth-child(5) a') + .waitForElementVisible('#tagged-path', 1000) + .assert.containsText('.view', '/a/b/c') .end() } }