@@ -745,22 +745,18 @@ module.exports = NavigationContext;
745
745
var invariant = _dereq_ ( 'react/lib/invariant' ) ;
746
746
var canUseDOM = _dereq_ ( 'react/lib/ExecutionEnvironment' ) . canUseDOM ;
747
747
var getWindowScrollPosition = _dereq_ ( '../utils/getWindowScrollPosition' ) ;
748
- var Path = _dereq_ ( '../utils/Path' ) ;
749
748
750
749
function shouldUpdateScroll ( state , prevState ) {
751
- if ( ! prevState ) {
750
+ if ( ! prevState )
752
751
return true ;
753
- }
754
752
755
- var path = state . path ;
753
+ // Don't update scroll position when only the query has changed.
754
+ if ( state . pathname === prevState . pathname )
755
+ return false ;
756
+
756
757
var routes = state . routes ;
757
- var prevPath = prevState . path ;
758
758
var prevRoutes = prevState . routes ;
759
759
760
- if ( Path . withoutQuery ( path ) === Path . withoutQuery ( prevPath ) ) {
761
- return false ;
762
- }
763
-
764
760
var sharedAncestorRoutes = routes . filter ( function ( route ) {
765
761
return prevRoutes . indexOf ( route ) !== - 1 ;
766
762
} ) ;
@@ -814,9 +810,8 @@ var Scrolling = {
814
810
} ,
815
811
816
812
_updateScroll : function ( prevState ) {
817
- if ( ! shouldUpdateScroll ( this . state , prevState ) ) {
813
+ if ( ! shouldUpdateScroll ( this . state , prevState ) )
818
814
return ;
819
- }
820
815
821
816
var scrollBehavior = this . getScrollBehavior ( ) ;
822
817
@@ -831,7 +826,7 @@ var Scrolling = {
831
826
832
827
module . exports = Scrolling ;
833
828
834
- } , { "../utils/Path" : 21 , "../utils/ getWindowScrollPosition" :28 , "react/lib/ExecutionEnvironment" :37 , "react/lib/invariant" :41 } ] , 18 :[ function ( _dereq_ , module , exports ) {
829
+ } , { "../utils/getWindowScrollPosition" :28 , "react/lib/ExecutionEnvironment" :37 , "react/lib/invariant" :41 } ] , 18 :[ function ( _dereq_ , module , exports ) {
835
830
var React = ( typeof window !== "undefined" ? window . React : typeof global !== "undefined" ? global . React : null ) ;
836
831
837
832
/**
@@ -857,6 +852,7 @@ var State = {
857
852
contextTypes : {
858
853
getCurrentPath : React . PropTypes . func . isRequired ,
859
854
getCurrentRoutes : React . PropTypes . func . isRequired ,
855
+ getCurrentPathname : React . PropTypes . func . isRequired ,
860
856
getCurrentParams : React . PropTypes . func . isRequired ,
861
857
getCurrentQuery : React . PropTypes . func . isRequired ,
862
858
isActive : React . PropTypes . func . isRequired
@@ -876,6 +872,13 @@ var State = {
876
872
return this . context . getCurrentRoutes ( ) ;
877
873
} ,
878
874
875
+ /**
876
+ * Returns the current URL path without the query string.
877
+ */
878
+ getPathname : function ( ) {
879
+ return this . context . getCurrentPathname ( ) ;
880
+ } ,
881
+
879
882
/**
880
883
* Returns an object of the URL params that are currently active.
881
884
*/
@@ -948,6 +951,13 @@ var StateContext = {
948
951
return this . state . routes . slice ( 0 ) ;
949
952
} ,
950
953
954
+ /**
955
+ * Returns the current URL path without the query string.
956
+ */
957
+ getCurrentPathname : function ( ) {
958
+ return this . state . pathname ;
959
+ } ,
960
+
951
961
/**
952
962
* Returns a read-only object of the currently active URL parameters.
953
963
*/
@@ -977,6 +987,7 @@ var StateContext = {
977
987
childContextTypes : {
978
988
getCurrentPath : React . PropTypes . func . isRequired ,
979
989
getCurrentRoutes : React . PropTypes . func . isRequired ,
990
+ getCurrentPathname : React . PropTypes . func . isRequired ,
980
991
getCurrentParams : React . PropTypes . func . isRequired ,
981
992
getCurrentQuery : React . PropTypes . func . isRequired ,
982
993
isActive : React . PropTypes . func . isRequired
@@ -986,6 +997,7 @@ var StateContext = {
986
997
return {
987
998
getCurrentPath : this . getCurrentPath ,
988
999
getCurrentRoutes : this . getCurrentRoutes ,
1000
+ getCurrentPathname : this . getCurrentPathname ,
989
1001
getCurrentParams : this . getCurrentParams ,
990
1002
getCurrentQuery : this . getCurrentQuery ,
991
1003
isActive : this . isActive
@@ -1605,11 +1617,11 @@ function createRouter(options) {
1605
1617
} ,
1606
1618
1607
1619
/**
1608
- * Performs a match of the given path against this router and returns an object with
1609
- * the { path, routes, params, query } that match. Returns null if no match can be made.
1620
+ * Performs a match of the given pathname against this router and returns an object
1621
+ * with the { routes, params } that match. Returns null if no match can be made.
1610
1622
*/
1611
- match : function ( path ) {
1612
- return findMatch ( Path . withoutQuery ( path ) , routes , this . defaultRoute , this . notFoundRoute ) || null ;
1623
+ match : function ( pathname ) {
1624
+ return findMatch ( pathname , routes , this . defaultRoute , this . notFoundRoute ) || null ;
1613
1625
} ,
1614
1626
1615
1627
/**
@@ -1630,19 +1642,21 @@ function createRouter(options) {
1630
1642
*/
1631
1643
dispatch : function ( path , action , callback ) {
1632
1644
if ( pendingTransition ) {
1633
- pendingTransition . abort ( new Cancellation ( ) ) ;
1645
+ pendingTransition . abort ( new Cancellation ) ;
1634
1646
pendingTransition = null ;
1635
1647
}
1636
1648
1637
1649
var prevPath = state . path ;
1638
1650
if ( prevPath === path )
1639
1651
return ; // Nothing to do!
1640
1652
1641
- if ( prevPath && action !== LocationActions . REPLACE ) {
1653
+ // Record the scroll position as early as possible to
1654
+ // get it before browsers try update it automatically.
1655
+ if ( prevPath && action !== LocationActions . REPLACE )
1642
1656
this . recordScrollPosition ( prevPath ) ;
1643
- }
1644
1657
1645
- var match = this . match ( path ) ;
1658
+ var pathname = Path . withoutQuery ( path ) ;
1659
+ var match = this . match ( pathname ) ;
1646
1660
1647
1661
warning (
1648
1662
match != null ,
@@ -1687,6 +1701,7 @@ function createRouter(options) {
1687
1701
1688
1702
nextState . path = path ;
1689
1703
nextState . action = action ;
1704
+ nextState . pathname = pathname ;
1690
1705
nextState . routes = nextRoutes ;
1691
1706
nextState . params = nextParams ;
1692
1707
nextState . query = nextQuery ;
@@ -2691,7 +2706,7 @@ var emptyFunction = _dereq_("./emptyFunction");
2691
2706
var warning = emptyFunction ;
2692
2707
2693
2708
if ( "production" !== "production" ) {
2694
- warning = function ( condition , format ) { for ( var args = [ ] , $__0 = 2 , $__1 = arguments . length ; $__0 < $__1 ; $__0 ++ ) args . push ( arguments [ $__0 ] ) ;
2709
+ warning = function ( condition , format ) { var args = Array . prototype . slice . call ( arguments , 2 ) ;
2695
2710
if ( format === undefined ) {
2696
2711
throw new Error (
2697
2712
'`warning(condition, format, ...args)` requires a warning ' +
0 commit comments