Skip to content

Commit 541a543

Browse files
fnlctrlyyx990803
authored andcommitted
Fix click event not bound for router-link (fix #707) (#708)
* Fix click event not bound for router-link (fix #707) Fix click event not bound for `<router-link>` when tag is not `<a>` and doesn't have child `<a>` * add e2e test
1 parent b79950d commit 541a543

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

examples/basic/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ new Vue({
3434
<li><router-link to="/">/</router-link></li>
3535
<li><router-link to="/foo">/foo</router-link></li>
3636
<li><router-link to="/bar">/bar</router-link></li>
37+
<router-link tag="li" to="/bar">/bar</router-link>
3738
</ul>
3839
<router-view class="view"></router-view>
3940
</div>

src/components/link.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ export default {
6464
aData.on = on
6565
const aAttrs = aData.attrs || (aData.attrs = {})
6666
aAttrs.href = href
67+
} else {
68+
// doesn't have <a> child, apply listener to self
69+
data.on = on
6770
}
6871
}
6972

test/e2e/specs/basic.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = {
33
browser
44
.url('http://localhost:8080/basic/')
55
.waitForElementVisible('#app', 1000)
6+
.assert.count('li', 4)
67
.assert.count('li a', 3)
78
// assert correct href with base
89
.assert.attributeContains('li:nth-child(1) a', 'href', '/basic/')
@@ -22,6 +23,10 @@ module.exports = {
2223
.assert.urlEquals('http://localhost:8080/basic/')
2324
.assert.containsText('.view', 'home')
2425

26+
.click('li:nth-child(4)')
27+
.assert.urlEquals('http://localhost:8080/basic/bar')
28+
.assert.containsText('.view', 'bar')
29+
2530
// check initial visit
2631
.url('http://localhost:8080/basic/foo')
2732
.waitForElementVisible('#app', 1000)

0 commit comments

Comments
 (0)