@@ -11,6 +11,14 @@ function isModifiedEvent(event) {
11
11
return ! ! ( event . metaKey || event . altKey || event . ctrlKey || event . shiftKey ) ;
12
12
}
13
13
14
+ function isEmptyObject ( object ) {
15
+ for ( var p in object )
16
+ if ( object . hasOwnProperty ( p ) )
17
+ return false ;
18
+
19
+ return true ;
20
+ }
21
+
14
22
/**
15
23
* A <Link> is used to create an <a> element that links to a route.
16
24
* When that route is active, the link gets an "active" class name
@@ -47,9 +55,8 @@ var Link = React.createClass({
47
55
48
56
getDefaultProps ( ) {
49
57
return {
50
- className : '' ,
51
- activeClassName : 'active' ,
52
58
onlyActiveOnIndex : false ,
59
+ className : '' ,
53
60
style : { }
54
61
} ;
55
62
} ,
@@ -83,26 +90,24 @@ var Link = React.createClass({
83
90
} ,
84
91
85
92
render ( ) {
86
- var { to, query, onlyActiveOnIndex } = this . props ;
87
-
88
- var props = {
89
- ...this . props ,
90
- onClick : this . handleClick
91
- } ;
92
-
93
93
var { history } = this . context ;
94
+ var { activeClassName, activeStyle, onlyActiveOnIndex, to, query, state, onClick, ...props } = this . props ;
95
+
96
+ props . onClick = this . handleClick ;
94
97
95
98
// Ignore if rendered outside the context
96
99
// of history, simplifies unit testing.
97
100
if ( history ) {
98
101
props . href = history . createHref ( to , query ) ;
99
102
100
- if ( history . isActive ( to , query , onlyActiveOnIndex ) ) {
101
- if ( props . activeClassName )
102
- props . className += props . className !== '' ? ` ${ props . activeClassName } ` : props . activeClassName ;
103
+ if ( activeClassName || ( activeStyle != null && ! isEmptyObject ( activeStyle ) ) ) {
104
+ if ( history . isActive ( to , query , onlyActiveOnIndex ) ) {
105
+ if ( activeClassName )
106
+ props . className += props . className === '' ? activeClassName : ` ${ activeClassName } ` ;
103
107
104
- if ( props . activeStyle )
105
- props . style = { ...props . style , ...props . activeStyle } ;
108
+ if ( activeStyle )
109
+ props . style = { ...props . style , ...activeStyle } ;
110
+ }
106
111
}
107
112
}
108
113
0 commit comments