Skip to content

Commit

Permalink
fix: revert #2713 (#2723)
Browse files Browse the repository at this point in the history
Closes #2719
  • Loading branch information
posva authored Apr 17, 2019
1 parent 8e55ae1 commit ec6eab7
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 4 deletions.
16 changes: 15 additions & 1 deletion examples/basic/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const router = new VueRouter({
// Route components will be rendered inside <router-view>.
new Vue({
router,
data: () => ({ n: 0 }),
template: `
<div id="app">
<h1>Basic</h1>
Expand All @@ -43,9 +44,22 @@ new Vue({
<li><router-link to="/é?t=%25ñ">/é?t=%ñ</router-link></li>
<li><router-link to="/é#%25ñ">/é#%25ñ</router-link></li>
</ul>
<button id="navigate-btn" @click="navigateAndIncrement">On Success</button>
<pre id="counter">{{ n }}</pre>
<pre id="query-t">{{ $route.query.t }}</pre>
<pre id="hash">{{ $route.hash }}</pre>
<router-view class="view"></router-view>
</div>
`
`,

methods: {
navigateAndIncrement () {
const increment = () => this.n++
if (this.$route.path === '/') {
this.$router.push('/foo', increment)
} else {
this.$router.push('/', increment)
}
}
}
}).$mount('#app')
4 changes: 3 additions & 1 deletion examples/lazy-loading-before-mount/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
13 changes: 13 additions & 0 deletions examples/lazy-loading/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<div>
<h2>Lazy with params</h2>
<pre id="tagged-path">{{ $route.path }}</pre>
</div>`
})
}, 200)
}) },
// Bar and Baz belong to the same root route
// and grouped in the same async chunk.
{ path: '/bar', component: Bar,
Expand All @@ -63,6 +75,7 @@ new Vue({
<li><router-link to="/foo">/foo</router-link></li>
<li><router-link to="/bar">/bar</router-link></li>
<li><router-link to="/bar/baz">/bar/baz</router-link></li>
<li><router-link to="/a/b/c">/a/b/c</router-link></li>
</ul>
<router-view class="view"></router-view>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/util/resolve-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function resolveAsyncComponents (matched: Array<RouteRecord>): Function {
match.components[key] = resolvedDef
pending--
if (pending <= 0) {
next(to)
next()
}
})

Expand Down
9 changes: 9 additions & 0 deletions test/e2e/specs/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
14 changes: 13 additions & 1 deletion test/e2e/specs/lazy-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()
}
}

0 comments on commit ec6eab7

Please sign in to comment.