File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -26,11 +26,26 @@ export default function (Vue) {
26
26
// don't redirect when preventDefault called
27
27
if ( e . defaultPrevented ) return
28
28
29
- if ( e . button === 0 ) {
29
+ if ( e . button !== 0 ) return
30
+
31
+ if ( this . el . tagName === 'A' ) {
32
+ // v-link on <a v-link="'path'">
30
33
e . preventDefault ( )
31
34
if ( this . destination != null ) {
32
35
router . go ( this . destination )
33
36
}
37
+ } else {
38
+ // v-link delegate on <div v-link>
39
+ var el = e . target
40
+ while ( el && el . tagName !== 'A' && el !== this . el ) {
41
+ el = el . parentNode
42
+ }
43
+ if ( ! el || el . tagName !== 'A' || ! el . href ) return
44
+
45
+ if ( sameOrigin ( el ) ) {
46
+ e . preventDefault ( )
47
+ router . go ( el . href )
48
+ }
34
49
}
35
50
}
36
51
this . el . addEventListener ( 'click' , this . handler )
@@ -88,4 +103,10 @@ export default function (Vue) {
88
103
this . unwatch && this . unwatch ( )
89
104
}
90
105
} )
106
+
107
+ function sameOrigin ( link ) {
108
+ return link . protocol === location . protocol &&
109
+ link . hostname === location . hostname &&
110
+ link . port === location . port
111
+ }
91
112
}
You can’t perform that action at this time.
0 commit comments