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) {
2626 // don't redirect when preventDefault called
2727 if ( e . defaultPrevented ) return
2828
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'">
3033 e . preventDefault ( )
3134 if ( this . destination != null ) {
3235 router . go ( this . destination )
3336 }
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+ }
3449 }
3550 }
3651 this . el . addEventListener ( 'click' , this . handler )
@@ -88,4 +103,10 @@ export default function (Vue) {
88103 this . unwatch && this . unwatch ( )
89104 }
90105 } )
106+
107+ function sameOrigin ( link ) {
108+ return link . protocol === location . protocol &&
109+ link . hostname === location . hostname &&
110+ link . port === location . port
111+ }
91112}
You can’t perform that action at this time.
0 commit comments