Skip to content

Commit

Permalink
Fix click event not bound for router-link (fix #707) (#708)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fnlctrl authored and yyx990803 committed Oct 13, 2016
1 parent b79950d commit 541a543
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/basic/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ new Vue({
<li><router-link to="/">/</router-link></li>
<li><router-link to="/foo">/foo</router-link></li>
<li><router-link to="/bar">/bar</router-link></li>
<router-link tag="li" to="/bar">/bar</router-link>
</ul>
<router-view class="view"></router-view>
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/components/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export default {
aData.on = on
const aAttrs = aData.attrs || (aData.attrs = {})
aAttrs.href = href
} else {
// doesn't have <a> child, apply listener to self
data.on = on
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/e2e/specs/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
browser
.url('http://localhost:8080/basic/')
.waitForElementVisible('#app', 1000)
.assert.count('li', 4)
.assert.count('li a', 3)
// assert correct href with base
.assert.attributeContains('li:nth-child(1) a', 'href', '/basic/')
Expand All @@ -22,6 +23,10 @@ module.exports = {
.assert.urlEquals('http://localhost:8080/basic/')
.assert.containsText('.view', 'home')

.click('li:nth-child(4)')
.assert.urlEquals('http://localhost:8080/basic/bar')
.assert.containsText('.view', 'bar')

// check initial visit
.url('http://localhost:8080/basic/foo')
.waitForElementVisible('#app', 1000)
Expand Down

0 comments on commit 541a543

Please sign in to comment.