Skip to content

Commit b4c341b

Browse files
ccbikaiyyx990803
authored andcommitted
fix a bug , in histroy mode, no same origin link be a path
1 parent 5953363 commit b4c341b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/directives/link.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const queryStringRE = /\?.*$/
77
// HTML5 history mode
88
export default function (Vue) {
99

10-
let _ = Vue.util
10+
const _ = Vue.util
11+
const urlParser = document.createElement('a')
1112

1213
Vue.directive('link', {
1314

@@ -48,18 +49,25 @@ export default function (Vue) {
4849

4950
if (this.el.tagName === 'A' || e.target === this.el) {
5051
// v-link on <a v-link="'path'">
51-
go(target)
52+
if (sameOrigin(this.el, target)) {
53+
go(target)
54+
} else if (typeof target === 'string') {
55+
window.location.href = target
56+
}
5257
} else {
5358
// v-link delegate on <div v-link>
5459
var el = e.target
5560
while (el && el.tagName !== 'A' && el !== this.el) {
5661
el = el.parentNode
5762
}
5863
if (!el) return
64+
if (!sameOrigin(el, target) && typeof target === 'string') {
65+
window.location.href = target
66+
}
5967
if (el.tagName !== 'A' || !el.href) {
6068
// allow not anchor
6169
go(target)
62-
} else if (sameOrigin(el)) {
70+
} else if (sameOrigin(el, target)) {
6371
go({
6472
path: el.pathname,
6573
replace: target && target.replace,
@@ -150,7 +158,12 @@ export default function (Vue) {
150158
}
151159
})
152160

153-
function sameOrigin (link) {
161+
function sameOrigin (link, target) {
162+
target = target || {}
163+
if (link.tagName !== 'A' && typeof target === 'string') {
164+
link = urlParser
165+
link.href = target
166+
}
154167
return link.protocol === location.protocol &&
155168
link.hostname === location.hostname &&
156169
link.port === location.port

0 commit comments

Comments
 (0)