@@ -70,6 +70,9 @@ var URLStore = {
70
70
if ( path === _currentPath )
71
71
return ;
72
72
73
+ if ( _location === 'disabledHistory' )
74
+ return window . location = path ;
75
+
73
76
if ( _location === 'history' ) {
74
77
window . history . pushState ( { path : path } , '' , path ) ;
75
78
notifyChange ( ) ;
@@ -87,7 +90,9 @@ var URLStore = {
87
90
* to the browser's history.
88
91
*/
89
92
replace : function ( path ) {
90
- if ( _location === 'history' ) {
93
+ if ( _location === 'disabledHistory' ) {
94
+ window . location . replace ( path ) ;
95
+ } else if ( _location === 'history' ) {
91
96
window . history . replaceState ( { path : path } , '' , path ) ;
92
97
notifyChange ( ) ;
93
98
} else if ( _location === 'hash' ) {
@@ -143,10 +148,15 @@ var URLStore = {
143
148
return ; // Don't setup twice.
144
149
}
145
150
151
+ if ( location === 'history' && ! supportsHistory ( ) ) {
152
+ location = 'disabledHistory' ;
153
+ return ;
154
+ }
155
+
146
156
var changeEvent = CHANGE_EVENTS [ location ] ;
147
157
148
158
invariant (
149
- changeEvent ,
159
+ changeEvent || location === 'disabledHistory' ,
150
160
'The URL store location "' + location + '" is not valid. ' +
151
161
'It must be either "hash" or "history"'
152
162
) ;
@@ -185,4 +195,19 @@ var URLStore = {
185
195
186
196
} ;
187
197
198
+ function supportsHistory ( ) {
199
+ /*! taken from modernizr
200
+ * https://github.com/Modernizr/Modernizr/blob/master/LICENSE
201
+ * https://github.com/Modernizr/Modernizr/blob/master/feature-detects/history.js
202
+ */
203
+ var ua = navigator . userAgent ;
204
+ if ( ( ua . indexOf ( 'Android 2.' ) !== - 1 ||
205
+ ( ua . indexOf ( 'Android 4.0' ) !== - 1 ) ) &&
206
+ ua . indexOf ( 'Mobile Safari' ) !== - 1 &&
207
+ ua . indexOf ( 'Chrome' ) === - 1 ) {
208
+ return false ;
209
+ }
210
+ return ( window . history && 'pushState' in window . history ) ;
211
+ }
212
+
188
213
module . exports = URLStore ;
0 commit comments