Skip to content

Commit 1e33f66

Browse files
committed
Merge pull request #204 from mopemope/noanchor
Fix: v-link should work on non-anchor elements
2 parents 314e722 + 8d3a3d8 commit 1e33f66

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/directives/link.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,22 @@ export default function (Vue) {
4242
while (el && el.tagName !== 'A' && el !== this.el) {
4343
el = el.parentNode
4444
}
45-
if (!el || el.tagName !== 'A' || !el.href) return
46-
if (sameOrigin(el)) {
45+
if (!el) return
46+
if (el.tagName !== 'A' || !el.href) {
47+
// allow not anchor
4748
e.preventDefault()
48-
router.go({
49-
path: el.pathname,
50-
replace: target && target.replace,
51-
append: target && target.append
52-
})
49+
if (target != null) {
50+
router.go(target)
51+
}
52+
} else {
53+
if (sameOrigin(el)) {
54+
e.preventDefault()
55+
router.go({
56+
path: el.pathname,
57+
replace: target && target.replace,
58+
append: target && target.append
59+
})
60+
}
5361
}
5462
}
5563
}

0 commit comments

Comments
 (0)