Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions modules/stores/URLStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ var URLStore = {
if (path === _currentPath)
return;

if (_location === 'disabledHistory')
return window.location = path;

if (_location === 'history') {
window.history.pushState({ path: path }, '', path);
notifyChange();
Expand All @@ -87,7 +90,9 @@ var URLStore = {
* to the browser's history.
*/
replace: function (path) {
if (_location === 'history') {
if (_location === 'disabledHistory') {
window.location.replace(path);
} else if (_location === 'history') {
window.history.replaceState({ path: path }, '', path);
notifyChange();
} else if (_location === 'hash') {
Expand Down Expand Up @@ -143,10 +148,15 @@ var URLStore = {
return; // Don't setup twice.
}

if (location === 'history' && !supportsHistory()) {
location = 'disabledHistory';
return;
}

var changeEvent = CHANGE_EVENTS[location];

invariant(
changeEvent,
changeEvent || location === 'disabledHistory',
'The URL store location "' + location + '" is not valid. ' +
'It must be either "hash" or "history"'
);
Expand Down Expand Up @@ -185,4 +195,19 @@ var URLStore = {

};

function supportsHistory() {
/*! taken from modernizr
* https://github.com/Modernizr/Modernizr/blob/master/LICENSE
* https://github.com/Modernizr/Modernizr/blob/master/feature-detects/history.js
*/
var ua = navigator.userAgent;
if ((ua.indexOf('Android 2.') !== -1 ||
(ua.indexOf('Android 4.0') !== -1)) &&
ua.indexOf('Mobile Safari') !== -1 &&
ua.indexOf('Chrome') === -1) {
return false;
}
return (window.history && 'pushState' in window.history);
}

module.exports = URLStore;