@@ -20,7 +20,11 @@ export default {
20
20
exact : Boolean ,
21
21
append : Boolean ,
22
22
replace : Boolean ,
23
- activeClass : String
23
+ activeClass : String ,
24
+ event : {
25
+ type : [ String , Array ] ,
26
+ default : 'click'
27
+ }
24
28
} ,
25
29
render ( h : Function ) {
26
30
const router = this . $router
@@ -33,23 +37,8 @@ export default {
33
37
? isSameRoute(current, compareTarget)
34
38
: isIncludedRoute(current, compareTarget)
35
39
36
- const on = {
37
- click : ( e ) = > {
38
- // don't redirect with control keys
39
- /* istanbul ignore if */
40
- if ( e . metaKey || e . ctrlKey || e . shiftKey ) return
41
- // don't redirect when preventDefault called
42
- /* istanbul ignore if */
43
- if ( e . defaultPrevented ) return
44
- // don't redirect on right click
45
- /* istanbul ignore if */
46
- if ( e . button !== 0 ) return
47
- // don't redirect if `target="_blank"`
48
- /* istanbul ignore if */
49
- const target = e . target . getAttribute ( 'target' )
50
- if ( / \b _ b l a n k \b / i. test ( target ) ) return
51
-
52
- e . preventDefault ( )
40
+ const handler = e => {
41
+ if ( guardEvent ( e ) ) {
53
42
if ( this . replace ) {
54
43
router . replace ( normalizedTo )
55
44
} else {
@@ -58,6 +47,13 @@ export default {
58
47
}
59
48
}
60
49
50
+ const on = { click : guardEvent }
51
+ if (Array.isArray(this.event)) {
52
+ this . event . forEach ( e => { on [ e ] = handler } )
53
+ } else {
54
+ on [ this . event ] = handler
55
+ }
56
+
61
57
const data: any = {
62
58
class : classes
63
59
}
@@ -86,6 +82,25 @@ export default {
86
82
}
87
83
}
88
84
85
+ function guardEvent ( e ) {
86
+ // don't redirect with control keys
87
+ /* istanbul ignore if */
88
+ if ( e . metaKey || e . ctrlKey || e . shiftKey ) return
89
+ // don't redirect when preventDefault called
90
+ /* istanbul ignore if */
91
+ if ( e . defaultPrevented ) return
92
+ // don't redirect on right click
93
+ /* istanbul ignore if */
94
+ if ( e . button !== 0 ) return
95
+ // don't redirect if `target="_blank"`
96
+ /* istanbul ignore if */
97
+ const target = e . target . getAttribute ( 'target' )
98
+ if ( / \b _ b l a n k \b / i. test ( target ) ) return
99
+
100
+ e . preventDefault ( )
101
+ return true
102
+ }
103
+
89
104
function findAnchor (children) {
90
105
if ( children ) {
91
106
let child
0 commit comments