File tree Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -81,8 +81,8 @@ export var Link = React.createClass({
81
81
82
82
// ignore if rendered outside of the context of a router, simplifies unit testing
83
83
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 ;
86
86
87
87
if ( props . activeStyle )
88
88
Object . assign ( props . style , props . activeStyle ) ;
Original file line number Diff line number Diff line change @@ -114,6 +114,50 @@ describe('A <Link>', function () {
114
114
} ) ;
115
115
} ) ;
116
116
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
+
117
161
describe ( 'when its route is active' , function ( ) {
118
162
it ( 'has its activeClassName' , function ( done ) {
119
163
var LinkWrapper = React . createClass ( {
You can’t perform that action at this time.
0 commit comments