@@ -329,7 +329,8 @@ var Route = React.createClass({
329329 propTypes : {
330330 handler : React . PropTypes . any . isRequired ,
331331 path : React . PropTypes . string ,
332- name : React . PropTypes . string
332+ name : React . PropTypes . string ,
333+ ignoreScrollBehavior : React . PropTypes . bool
333334 } ,
334335
335336 render : function ( ) {
@@ -509,6 +510,16 @@ function updateMatchComponents(matches, refs) {
509510 }
510511}
511512
513+ function shouldUpdateScroll ( currentMatches , previousMatches ) {
514+ var commonMatches = currentMatches . filter ( function ( match ) {
515+ return previousMatches . indexOf ( match ) !== - 1 ;
516+ } ) ;
517+
518+ return ! commonMatches . some ( function ( match ) {
519+ return match . route . props . ignoreScrollBehavior ;
520+ } ) ;
521+ }
522+
512523function returnNull ( ) {
513524 return null ;
514525}
@@ -581,17 +592,11 @@ var Routes = React.createClass({
581592 'inside some other component\'s render method'
582593 ) ;
583594
584- if ( this . _handleStateChange ) {
585- this . _handleStateChange ( ) ;
586- delete this . _handleStateChange ;
587- }
595+ this . _handleStateChange ( ) ;
588596 } ,
589597
590598 componentDidUpdate : function ( ) {
591- if ( this . _handleStateChange ) {
592- this . _handleStateChange ( ) ;
593- delete this . _handleStateChange ;
594- }
599+ this . _handleStateChange ( ) ;
595600 } ,
596601
597602 /**
@@ -631,16 +636,25 @@ var Routes = React.createClass({
631636 } else if ( abortReason ) {
632637 this . goBack ( ) ;
633638 } else {
634- this . _handleStateChange = this . handleStateChange . bind ( this , path , actionType ) ;
639+ this . _nextStateChangeHandler = this . _finishTransitionTo . bind ( this , path , actionType , this . state . matches ) ;
635640 this . setState ( nextState ) ;
636641 }
637642 } ) ;
638643 } ,
639644
640- handleStateChange : function ( path , actionType ) {
641- updateMatchComponents ( this . state . matches , this . refs ) ;
645+ _handleStateChange : function ( ) {
646+ if ( this . _nextStateChangeHandler ) {
647+ this . _nextStateChangeHandler ( ) ;
648+ delete this . _nextStateChangeHandler ;
649+ }
650+ } ,
651+
652+ _finishTransitionTo : function ( path , actionType , previousMatches ) {
653+ var currentMatches = this . state . matches ;
654+ updateMatchComponents ( currentMatches , this . refs ) ;
642655
643- this . updateScroll ( path , actionType ) ;
656+ if ( shouldUpdateScroll ( currentMatches , previousMatches ) )
657+ this . updateScroll ( path , actionType ) ;
644658
645659 if ( this . props . onChange )
646660 this . props . onChange . call ( this ) ;
0 commit comments