@@ -7,7 +7,6 @@ const queryStringRE = /\?.*$/
7
7
// HTML5 history mode
8
8
export default function ( Vue ) {
9
9
10
- const urlParser = document . createElement ( 'a' )
11
10
const {
12
11
bind,
13
12
isObject,
@@ -69,42 +68,29 @@ export default function (Vue) {
69
68
70
69
onClick ( e ) {
71
70
// don't redirect with control keys
71
+ /* istanbul ignore if */
72
72
if ( e . metaKey || e . ctrlKey || e . shiftKey ) return
73
73
// don't redirect when preventDefault called
74
+ /* istanbul ignore if */
74
75
if ( e . defaultPrevented ) return
75
76
// don't redirect on right click
77
+ /* istanbul ignore if */
76
78
if ( e . button !== 0 ) return
77
79
78
80
const target = this . target
79
- const go = ( target ) => {
81
+ if ( target ) {
82
+ // v-link with expression, just go
80
83
e . preventDefault ( )
81
- if ( target != null ) {
82
- this . router . go ( target )
83
- }
84
- }
85
-
86
- if ( this . el . tagName === 'A' || e . target === this . el ) {
87
- // v-link on <a v-link="'path'">
88
- if ( sameOrigin ( this . el , target ) ) {
89
- go ( target )
90
- } else if ( typeof target === 'string' ) {
91
- window . location . href = target
92
- }
84
+ this . router . go ( target )
93
85
} else {
94
- // v-link delegate on <div v-link>
86
+ // no expression, delegate for an <a> inside
95
87
var el = e . target
96
- while ( el && el . tagName !== 'A' && el !== this . el ) {
88
+ while ( el . tagName !== 'A' && el !== this . el ) {
97
89
el = el . parentNode
98
90
}
99
- if ( ! el ) return
100
- if ( ! sameOrigin ( el , target ) && typeof target === 'string' ) {
101
- window . location . href = target
102
- }
103
- if ( el . tagName !== 'A' || ! el . href ) {
104
- // allow not anchor
105
- go ( target )
106
- } else if ( sameOrigin ( el , target ) ) {
107
- go ( {
91
+ if ( el . tagName === 'A' && sameOrigin ( el ) ) {
92
+ e . preventDefault ( )
93
+ this . router . go ( {
108
94
path : el . pathname ,
109
95
replace : target && target . replace ,
110
96
append : target && target . append
@@ -196,12 +182,7 @@ export default function (Vue) {
196
182
}
197
183
} )
198
184
199
- function sameOrigin ( link , target ) {
200
- target = target || { }
201
- if ( link . tagName !== 'A' && typeof target === 'string' ) {
202
- link = urlParser
203
- link . href = target
204
- }
185
+ function sameOrigin ( link ) {
205
186
return link . protocol === location . protocol &&
206
187
link . hostname === location . hostname &&
207
188
link . port === location . port
0 commit comments