react-router
Version:
A complete routing library for React.js
55 lines (46 loc) • 1.84 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.getHashPath = getHashPath;
exports.replaceHashPath = replaceHashPath;
exports.getWindowPath = getWindowPath;
exports.getWindowScrollPosition = getWindowScrollPosition;
exports.setWindowScrollPosition = setWindowScrollPosition;
exports.supportsHistory = supportsHistory;
var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
exports.canUseDOM = canUseDOM;
function getHashPath() {
return decodeURI(
// We can't use window.location.hash here because it's not
// consistent across browsers - Firefox will pre-decode it!
window.location.href.split('#')[1] || '');
}
function replaceHashPath(path) {
window.location.replace(window.location.pathname + window.location.search + '#' + path);
}
function getWindowPath() {
return decodeURI(window.location.pathname + window.location.search);
}
function getWindowScrollPosition() {
return {
scrollX: window.pageXOffset || document.documentElement.scrollLeft,
scrollY: window.pageYOffset || document.documentElement.scrollTop
};
}
function setWindowScrollPosition(scrollX, scrollY) {
window.scrollTo(scrollX, scrollY);
}
/**
* taken from modernizr
* https://github.com/Modernizr/Modernizr/blob/master/LICENSE
* https://github.com/Modernizr/Modernizr/blob/master/feature-detects/history.js
* changed to avoid false negatives for Windows Phones: https://github.com/rackt/react-router/issues/586
*/
function supportsHistory() {
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 && ua.indexOf('Windows Phone') === -1) {
return false;
}
return window.history && 'pushState' in window.history;
}