UNPKG

cycle-router

Version:
41 lines (32 loc) 1.53 kB
'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.makePushState = exports.makeHistory = undefined; var _history = require('history'); 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 the regular check return window.history && 'pushState' in window.history; } function makeHistory(hash, options) { var useHash = hash || !supportsHistory(); return useHash ? (0, _history.useQueries)((0, _history.useBasename)(_history.createHashHistory))(options) : (0, _history.useQueries)((0, _history.useBasename)(_history.createHistory))(options); } function makePushState(history) { return function pushState(url) { if ('string' === typeof url || 'object' === (typeof url === 'undefined' ? 'undefined' : _typeof(url))) { history.push(url); } else { throw new Error('Router Driver input must be a string or\n object but received ' + (typeof url === 'undefined' ? 'undefined' : _typeof(url))); } }; } exports.makeHistory = makeHistory; exports.makePushState = makePushState;