Skip to content

Commit

Permalink
fix(link): merge event listeners when provided in an anchor
Browse files Browse the repository at this point in the history
Fix #2890
  • Loading branch information
posva committed Aug 21, 2019
1 parent 5ef5d73 commit e0d4dc4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/components/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,24 @@ export default {
// in case the <a> is a static node
a.isStatic = false
const aData = (a.data = extend({}, a.data))
aData.on = on
aData.on = aData.on || {}
// transform existing events in both objects into arrays so we can push later
for (const event in aData.on) {
const handler = aData.on[event]
if (event in on) {
aData.on[event] = Array.isArray(handler) ? handler : [handler]
}
}
// append new listeners for router-link
for (const event in on) {
if (event in aData.on) {
// on[event] is always a function
aData.on[event].push(on[event])
} else {
aData.on[event] = handler
}
}

const aAttrs = (a.data.attrs = extend({}, a.data.attrs))
aAttrs.href = href
} else {
Expand Down

0 comments on commit e0d4dc4

Please sign in to comment.