@@ -578,9 +578,7 @@ var HistoryLocation = {
578
578
notifyChange ( LocationActions . REPLACE ) ;
579
579
} ,
580
580
581
- pop : function ( ) {
582
- History . back ( ) ;
583
- } ,
581
+ pop : History . back ,
584
582
585
583
getCurrentPath : getWindowPath ,
586
584
@@ -1071,7 +1069,7 @@ var canUseDOM = _dereq_('react/lib/ExecutionEnvironment').canUseDOM;
1071
1069
var History = {
1072
1070
1073
1071
/**
1074
- * Sends the browser back one entry in the history, if one is available .
1072
+ * Sends the browser back one entry in the history.
1075
1073
*/
1076
1074
back : function ( ) {
1077
1075
invariant (
@@ -1443,7 +1441,6 @@ module.exports = Transition;
1443
1441
1444
1442
} , { "./Promise" :24 , "./Redirect" :26 , "./reversedArray" :31 , "react/lib/Object.assign" :40 } ] , 28 :[ function ( _dereq_ , module , exports ) {
1445
1443
/* jshint -W058 */
1446
-
1447
1444
var React = ( typeof window !== "undefined" ? window . React : typeof global !== "undefined" ? global . React : null ) ;
1448
1445
var warning = _dereq_ ( 'react/lib/warning' ) ;
1449
1446
var invariant = _dereq_ ( 'react/lib/invariant' ) ;
@@ -1536,22 +1533,32 @@ function createMatch(route, params) {
1536
1533
return { routes : [ route ] , params : params } ;
1537
1534
}
1538
1535
1539
- function hasMatch ( routes , route , prevParams , nextParams ) {
1536
+ function hasProperties ( object , properties ) {
1537
+ for ( var propertyName in properties )
1538
+ if ( properties . hasOwnProperty ( propertyName ) && object [ propertyName ] !== properties [ propertyName ] )
1539
+ return false ;
1540
+
1541
+ return true ;
1542
+ }
1543
+
1544
+ function hasMatch ( routes , route , prevParams , nextParams , prevQuery , nextQuery ) {
1540
1545
return routes . some ( function ( r ) {
1541
1546
if ( r !== route )
1542
1547
return false ;
1543
1548
1544
1549
var paramNames = route . paramNames ;
1545
1550
var paramName ;
1546
1551
1552
+ // Ensure that all params the route cares about did not change.
1547
1553
for ( var i = 0 , len = paramNames . length ; i < len ; ++ i ) {
1548
1554
paramName = paramNames [ i ] ;
1549
1555
1550
1556
if ( nextParams [ paramName ] !== prevParams [ paramName ] )
1551
1557
return false ;
1552
1558
}
1553
1559
1554
- return true ;
1560
+ // Ensure the query hasn't changed.
1561
+ return hasProperties ( prevQuery , nextQuery ) && hasProperties ( nextQuery , prevQuery ) ;
1555
1562
} ) ;
1556
1563
}
1557
1564
@@ -1598,6 +1605,20 @@ function createRouter(options) {
1598
1605
nextState = { } ;
1599
1606
}
1600
1607
1608
+ if ( typeof location === 'string' ) {
1609
+ warning (
1610
+ ! canUseDOM || "production" === 'test' ,
1611
+ 'You should not use a static location in a DOM environment because ' +
1612
+ 'the router will not be kept in sync with the current URL'
1613
+ ) ;
1614
+ } else {
1615
+ invariant (
1616
+ canUseDOM ,
1617
+ 'You cannot use %s without a DOM' ,
1618
+ location
1619
+ ) ;
1620
+ }
1621
+
1601
1622
// Automatically fall back to full page refreshes in
1602
1623
// browsers that don't support the HTML history API.
1603
1624
if ( location === HistoryLocation && ! supportsHistory ( ) )
@@ -1687,16 +1708,23 @@ function createRouter(options) {
1687
1708
} ,
1688
1709
1689
1710
/**
1690
- * Transitions to the previous URL. Returns true if the router
1691
- * was able to go back, false otherwise.
1711
+ * Transitions to the previous URL if one is available. Returns true if the
1712
+ * router was able to go back, false otherwise.
1713
+ *
1714
+ * Note: The router only tracks history entries in your application, not the
1715
+ * current browser session, so you can safely call this function without guarding
1716
+ * against sending the user back to some other site. However, when using
1717
+ * RefreshLocation (which is the fallback for HistoryLocation in browsers that
1718
+ * don't support HTML5 history) this method will *always* send the client back
1719
+ * because we cannot reliably track history length.
1692
1720
*/
1693
1721
goBack : function ( ) {
1694
1722
invariant (
1695
1723
typeof location !== 'string' ,
1696
1724
'You cannot use goBack with a static location'
1697
1725
) ;
1698
1726
1699
- if ( History . length > 1 ) {
1727
+ if ( History . length > 1 || location === RefreshLocation ) {
1700
1728
location . pop ( ) ;
1701
1729
return true ;
1702
1730
}
@@ -1759,6 +1787,7 @@ function createRouter(options) {
1759
1787
1760
1788
var prevRoutes = state . routes || [ ] ;
1761
1789
var prevParams = state . params || { } ;
1790
+ var prevQuery = state . query || { } ;
1762
1791
1763
1792
var nextRoutes = match . routes || [ ] ;
1764
1793
var nextParams = match . params || { } ;
@@ -1767,27 +1796,17 @@ function createRouter(options) {
1767
1796
var fromRoutes , toRoutes ;
1768
1797
if ( prevRoutes . length ) {
1769
1798
fromRoutes = prevRoutes . filter ( function ( route ) {
1770
- return ! hasMatch ( nextRoutes , route , prevParams , nextParams ) ;
1799
+ return ! hasMatch ( nextRoutes , route , prevParams , nextParams , prevQuery , nextQuery ) ;
1771
1800
} ) ;
1772
1801
1773
1802
toRoutes = nextRoutes . filter ( function ( route ) {
1774
- return ! hasMatch ( prevRoutes , route , prevParams , nextParams ) ;
1803
+ return ! hasMatch ( prevRoutes , route , prevParams , nextParams , prevQuery , nextQuery ) ;
1775
1804
} ) ;
1776
1805
} else {
1777
1806
fromRoutes = [ ] ;
1778
1807
toRoutes = nextRoutes ;
1779
1808
}
1780
1809
1781
- // If routes' hooks arrays are empty, then we transition to current route.
1782
- // But path is somehow still get changed.
1783
- // That could be only because of route query changes.
1784
- // Need to push current route to routes' hooks arrays.
1785
- if ( ! toRoutes . length && ! fromRoutes . length ) {
1786
- var currentRoute = state . routes [ state . routes . length - 1 ] ;
1787
- fromRoutes = [ currentRoute ] ;
1788
- toRoutes = [ currentRoute ] ;
1789
- }
1790
-
1791
1810
var transition = new Transition ( path , this . replaceWith . bind ( this , path ) ) ;
1792
1811
pendingTransition = transition ;
1793
1812
@@ -1832,21 +1851,8 @@ function createRouter(options) {
1832
1851
} ;
1833
1852
1834
1853
if ( typeof location === 'string' ) {
1835
- warning (
1836
- ! canUseDOM || "production" === 'test' ,
1837
- 'You should not use a static location in a DOM environment because ' +
1838
- 'the router will not be kept in sync with the current URL'
1839
- ) ;
1840
-
1841
- // Dispatch the location.
1842
1854
router . dispatch ( location , null , dispatchHandler ) ;
1843
1855
} else {
1844
- invariant (
1845
- canUseDOM ,
1846
- 'You cannot use %s in a non-DOM environment' ,
1847
- location
1848
- ) ;
1849
-
1850
1856
// Listen for changes to the location.
1851
1857
var changeListener = function ( change ) {
1852
1858
router . dispatch ( change . path , change . type , dispatchHandler ) ;
@@ -1931,7 +1937,6 @@ module.exports = createRouter;
1931
1937
1932
1938
} , { "../actions/LocationActions" :1 , "../behaviors/ImitateBrowserBehavior" :2 , "../components/RouteHandler" :9 , "../locations/HashLocation" :11 , "../locations/HistoryLocation" :12 , "../locations/RefreshLocation" :13 , "../mixins/NavigationContext" :16 , "../mixins/Scrolling" :18 , "../mixins/StateContext" :20 , "./Cancellation" :21 , "./History" :22 , "./Path" :23 , "./PropTypes" :25 , "./Redirect" :26 , "./Transition" :27 , "./createRoutesFromChildren" :29 , "./supportsHistory" :33 , "react/lib/ExecutionEnvironment" :39 , "react/lib/invariant" :43 , "react/lib/warning" :44 } ] , 29 :[ function ( _dereq_ , module , exports ) {
1933
1939
/* jshint -W084 */
1934
-
1935
1940
var React = ( typeof window !== "undefined" ? window . React : typeof global !== "undefined" ? global . React : null ) ;
1936
1941
var warning = _dereq_ ( 'react/lib/warning' ) ;
1937
1942
var invariant = _dereq_ ( 'react/lib/invariant' ) ;
@@ -2818,7 +2823,7 @@ var emptyFunction = _dereq_("./emptyFunction");
2818
2823
var warning = emptyFunction ;
2819
2824
2820
2825
if ( "production" !== "production" ) {
2821
- warning = function ( condition , format ) { var args = Array . prototype . slice . call ( arguments , 2 ) ;
2826
+ warning = function ( condition , format ) { for ( var args = [ ] , $__0 = 2 , $__1 = arguments . length ; $__0 < $__1 ; $__0 ++ ) args . push ( arguments [ $__0 ] ) ;
2822
2827
if ( format === undefined ) {
2823
2828
throw new Error (
2824
2829
'`warning(condition, format, ...args)` requires a warning ' +
0 commit comments