@@ -7,7 +7,8 @@ const queryStringRE = /\?.*$/
7
7
// HTML5 history mode
8
8
export default function ( Vue ) {
9
9
10
- let _ = Vue . util
10
+ const _ = Vue . util
11
+ const urlParser = document . createElement ( 'a' )
11
12
12
13
Vue . directive ( 'link' , {
13
14
@@ -48,18 +49,25 @@ export default function (Vue) {
48
49
49
50
if ( this . el . tagName === 'A' || e . target === this . el ) {
50
51
// 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
+ }
52
57
} else {
53
58
// v-link delegate on <div v-link>
54
59
var el = e . target
55
60
while ( el && el . tagName !== 'A' && el !== this . el ) {
56
61
el = el . parentNode
57
62
}
58
63
if ( ! el ) return
64
+ if ( ! sameOrigin ( el , target ) && typeof target === 'string' ) {
65
+ window . location . href = target
66
+ }
59
67
if ( el . tagName !== 'A' || ! el . href ) {
60
68
// allow not anchor
61
69
go ( target )
62
- } else if ( sameOrigin ( el ) ) {
70
+ } else if ( sameOrigin ( el , target ) ) {
63
71
go ( {
64
72
path : el . pathname ,
65
73
replace : target && target . replace ,
@@ -150,7 +158,12 @@ export default function (Vue) {
150
158
}
151
159
} )
152
160
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
+ }
154
167
return link . protocol === location . protocol &&
155
168
link . hostname === location . hostname &&
156
169
link . port === location . port
0 commit comments