react-view-router
Version:
react-view-router
40 lines (37 loc) • 1.59 kB
JavaScript
import { HistoryType } from './types';
import { getPossibleHashType, createHref } from './utils';
import { createHistory } from './history';
/**
* A browser history stores the current location in regular URLs in a web
* browser environment. This is the standard for most web apps and provides the
* cleanest URLs the browser's address bar.
*
* @see https://github.com/ReactTraining/history/tree/master/docs/api-reference.md#browserhistory
*/
export function createBrowserHref(to, hashType) {
return createHref(to, hashType);
}
/**
* Browser history stores the location in regular URLs. This is the standard for
* most web apps, but it requires some configuration on the server to ensure you
* serve the same app at multiple URLs.
*
* @see https://github.com/ReactTraining/history/tree/master/docs/api-reference.md#createbrowserhistory
*/
export function createBrowserHistory(options = {}) {
var _globalThis$document;
var _options$window = options.window,
_window = _options$window === void 0 ? (_globalThis$document = globalThis.document) === null || _globalThis$document === void 0 ? void 0 : _globalThis$document.defaultView : _options$window;
var _options$hashType = options.hashType,
hashType = _options$hashType === void 0 ? getPossibleHashType(_window) : _options$hashType;
var type = HistoryType.browser;
var history = createHistory({
window: _window,
type,
getLocationPath: () => _window.location,
createHref: to => createBrowserHref(to, hashType),
extra: options.extra
});
return history;
}
//# sourceMappingURL=browser.js.map