Skip to content

Commit e5f0964

Browse files
committed
adjust <router-link> click listener target when wrapping <a>
1 parent e0de642 commit e5f0964

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/components/link.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,30 @@ export default {
3838
? isSameRoute(current, compareTarget)
3939
: isIncludedRoute(current, compareTarget)
4040

41-
const data: any = {
42-
class: classes,
43-
on: {
44-
click: (e) => {
45-
e.preventDefault()
46-
if (this.replace) {
47-
router.replace(to)
48-
} else {
49-
router.push(to)
50-
}
41+
const on = {
42+
click: (e) => {
43+
e.preventDefault()
44+
if (this.replace) {
45+
router.replace(to)
46+
} else {
47+
router.push(to)
5148
}
5249
}
5350
}
5451

52+
const data: any = {
53+
class: classes
54+
}
55+
5556
if (this.tag === 'a') {
57+
data.on = on
5658
data.attrs = { href }
5759
} else {
58-
// find the first <a> child and apply href
60+
// find the first <a> child and apply listener and href
5961
const a = findAnchor(this.$slots.default)
6062
if (a) {
6163
const aData = a.data || (a.data = {})
64+
aData.on = on
6265
const aAttrs = aData.attrs || (aData.attrs = {})
6366
aAttrs.href = href
6467
}

0 commit comments

Comments
 (0)