File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -81,8 +81,8 @@ export var Link = React.createClass({
8181
8282 // ignore if rendered outside of the context of a router, simplifies unit testing
8383 if ( router && router . isActive ( to , query ) ) {
84- if ( props . activeClassName )
85- props . className += ` ${ props . activeClassName } ` ;
84+ if ( props . activeClassName )
85+ props . className += props . className !== '' ? ` ${ props . activeClassName } ` : props . activeClassName ;
8686
8787 if ( props . activeStyle )
8888 Object . assign ( props . style , props . activeStyle ) ;
Original file line number Diff line number Diff line change @@ -114,6 +114,50 @@ describe('A <Link>', function () {
114114 } ) ;
115115 } ) ;
116116
117+ describe ( 'when its route is active and className is empty' , function ( ) {
118+ it ( 'it shouldn\'t have an active class' , function ( done ) {
119+ var LinkWrapper = React . createClass ( {
120+ render ( ) {
121+ return (
122+ < div >
123+ < Link to = "hello" className = "dontKillMe" activeClassName = "" > Link</ Link >
124+ { this . props . children }
125+ </ div >
126+ ) ;
127+ }
128+ } ) ;
129+
130+ var a , steps = [
131+ function ( ) {
132+ a = div . querySelector ( 'a' ) ;
133+ expect ( a . className ) . toEqual ( 'dontKillMe' ) ;
134+ this . transitionTo ( 'hello' ) ;
135+ } ,
136+ function ( ) {
137+ expect ( a . className ) . toEqual ( 'dontKillMe' ) ;
138+ done ( ) ;
139+ }
140+ ] ;
141+
142+ function execNextStep ( ) {
143+ try {
144+ steps . shift ( ) . apply ( this , arguments ) ;
145+ } catch ( error ) {
146+ done ( error ) ;
147+ }
148+ }
149+
150+ render ( (
151+ < Router history = { new MemoryHistory ( '/goodbye' ) } onUpdate = { execNextStep } >
152+ < Route path = "/" component = { LinkWrapper } >
153+ < Route path = "goodbye" component = { Goodbye } />
154+ < Route path = "hello" component = { Hello } />
155+ </ Route >
156+ </ Router >
157+ ) , div , execNextStep ) ;
158+ } ) ;
159+ } ) ;
160+
117161 describe ( 'when its route is active' , function ( ) {
118162 it ( 'has its activeClassName' , function ( done ) {
119163 var LinkWrapper = React . createClass ( {
You can’t perform that action at this time.
0 commit comments