File tree 2 files changed +21
-3
lines changed
2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,13 @@ name through the link's properties to the resulting url.
27
27
The className a ` Link ` receives when it's route is active. Defaults to
28
28
` active ` .
29
29
30
+ ### ` onClick `
31
+
32
+ A custom handler for the click event. Works just like a handler on an ` <a> `
33
+ tag - calling ` e.preventDefault() ` or returning ` false ` will prevent the
34
+ transition from firing, while ` e.stopPropagation() ` will prevent the event
35
+ from bubbling.
36
+
30
37
### * others*
31
38
32
39
You can also pass props you'd like to be on the ` <a> ` such as a title, id, or className.
Original file line number Diff line number Diff line change @@ -52,7 +52,8 @@ var Link = React.createClass({
52
52
propTypes : {
53
53
to : React . PropTypes . string . isRequired ,
54
54
activeClassName : React . PropTypes . string . isRequired ,
55
- query : React . PropTypes . object
55
+ query : React . PropTypes . object ,
56
+ onClick : React . PropTypes . func
56
57
} ,
57
58
58
59
getDefaultProps : function ( ) {
@@ -108,13 +109,23 @@ var Link = React.createClass({
108
109
} ) ;
109
110
} ,
110
111
111
- handleClick : function ( event ) {
112
+ handleClick : function ( event ) {
113
+ var allowTransition = true ;
114
+ var ret ;
115
+
116
+ if ( this . props . onClick )
117
+ ret = this . props . onClick ( event ) ;
118
+
112
119
if ( isModifiedEvent ( event ) || ! isLeftClick ( event ) )
113
120
return ;
114
121
122
+ if ( ret === false || event . preventDefaulted === true )
123
+ allowTransition = false ;
124
+
115
125
event . preventDefault ( ) ;
116
126
117
- transitionTo ( this . props . to , this . getParams ( ) , this . props . query ) ;
127
+ if ( allowTransition )
128
+ transitionTo ( this . props . to , this . getParams ( ) , this . props . query ) ;
118
129
} ,
119
130
120
131
render : function ( ) {
You can’t perform that action at this time.
0 commit comments