@@ -11,6 +11,14 @@ function isModifiedEvent(event) {
1111 return ! ! ( event . metaKey || event . altKey || event . ctrlKey || event . shiftKey ) ;
1212}
1313
14+ function isEmptyObject ( object ) {
15+ for ( var p in object )
16+ if ( object . hasOwnProperty ( p ) )
17+ return false ;
18+
19+ return true ;
20+ }
21+
1422/**
1523 * A <Link> is used to create an <a> element that links to a route.
1624 * When that route is active, the link gets an "active" class name
@@ -47,9 +55,8 @@ var Link = React.createClass({
4755
4856 getDefaultProps ( ) {
4957 return {
50- className : '' ,
51- activeClassName : 'active' ,
5258 onlyActiveOnIndex : false ,
59+ className : '' ,
5360 style : { }
5461 } ;
5562 } ,
@@ -83,26 +90,24 @@ var Link = React.createClass({
8390 } ,
8491
8592 render ( ) {
86- var { to, query, onlyActiveOnIndex } = this . props ;
87-
88- var props = {
89- ...this . props ,
90- onClick : this . handleClick
91- } ;
92-
9393 var { history } = this . context ;
94+ var { activeClassName, activeStyle, onlyActiveOnIndex, to, query, state, onClick, ...props } = this . props ;
95+
96+ props . onClick = this . handleClick ;
9497
9598 // Ignore if rendered outside the context
9699 // of history, simplifies unit testing.
97100 if ( history ) {
98101 props . href = history . createHref ( to , query ) ;
99102
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 } ` ;
103107
104- if ( props . activeStyle )
105- props . style = { ...props . style , ...props . activeStyle } ;
108+ if ( activeStyle )
109+ props . style = { ...props . style , ...activeStyle } ;
110+ }
106111 }
107112 }
108113
0 commit comments