File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -194,6 +194,13 @@ var Routes = React.createClass({
194
194
} ;
195
195
} ,
196
196
197
+ componentDidMount : function ( ) {
198
+ if ( this . _initialSetStateCallback ) {
199
+ this . _initialSetStateCallback ( ) ;
200
+ delete this . _initialSetStateCallback ;
201
+ }
202
+ } ,
203
+
197
204
/**
198
205
* Performs a depth-first search for the first route in the tree that matches on
199
206
* the given path. Returns an array of all routes in the tree leading to the one
@@ -236,14 +243,23 @@ var Routes = React.createClass({
236
243
} else if ( abortReason ) {
237
244
this . goBack ( ) ;
238
245
} else {
239
- this . setState ( nextState , function ( ) {
246
+ var handleStateChange = function ( ) {
240
247
updateMatchComponents ( this . state . matches , this . refs ) ;
241
248
242
249
this . updateScroll ( path , actionType ) ;
243
250
244
251
if ( this . props . onChange )
245
252
this . props . onChange . call ( this ) ;
246
- } . bind ( this ) ) ;
253
+ } . bind ( this ) ;
254
+
255
+ if ( this . isMounted ( ) ) {
256
+ this . setState ( nextState , handleStateChange ) ;
257
+ } else {
258
+ // React does not invoke setState callback if we're still mounting
259
+ // so we have to store it and invoke in componentDidMount.
260
+ this . _initialSetStateCallback = handleStateChange ;
261
+ this . setState ( nextState ) ;
262
+ }
247
263
}
248
264
} . bind ( this ) ) ;
249
265
} ,
You can’t perform that action at this time.
0 commit comments