@@ -329,7 +329,8 @@ var Route = React.createClass({
329
329
propTypes : {
330
330
handler : React . PropTypes . any . isRequired ,
331
331
path : React . PropTypes . string ,
332
- name : React . PropTypes . string
332
+ name : React . PropTypes . string ,
333
+ ignoreScrollBehavior : React . PropTypes . bool
333
334
} ,
334
335
335
336
render : function ( ) {
@@ -509,6 +510,16 @@ function updateMatchComponents(matches, refs) {
509
510
}
510
511
}
511
512
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
+
512
523
function returnNull ( ) {
513
524
return null ;
514
525
}
@@ -581,17 +592,11 @@ var Routes = React.createClass({
581
592
'inside some other component\'s render method'
582
593
) ;
583
594
584
- if ( this . _handleStateChange ) {
585
- this . _handleStateChange ( ) ;
586
- delete this . _handleStateChange ;
587
- }
595
+ this . _handleStateChange ( ) ;
588
596
} ,
589
597
590
598
componentDidUpdate : function ( ) {
591
- if ( this . _handleStateChange ) {
592
- this . _handleStateChange ( ) ;
593
- delete this . _handleStateChange ;
594
- }
599
+ this . _handleStateChange ( ) ;
595
600
} ,
596
601
597
602
/**
@@ -631,16 +636,25 @@ var Routes = React.createClass({
631
636
} else if ( abortReason ) {
632
637
this . goBack ( ) ;
633
638
} else {
634
- this . _handleStateChange = this . handleStateChange . bind ( this , path , actionType ) ;
639
+ this . _nextStateChangeHandler = this . _finishTransitionTo . bind ( this , path , actionType , this . state . matches ) ;
635
640
this . setState ( nextState ) ;
636
641
}
637
642
} ) ;
638
643
} ,
639
644
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 ) ;
642
655
643
- this . updateScroll ( path , actionType ) ;
656
+ if ( shouldUpdateScroll ( currentMatches , previousMatches ) )
657
+ this . updateScroll ( path , actionType ) ;
644
658
645
659
if ( this . props . onChange )
646
660
this . props . onChange . call ( this ) ;
0 commit comments