react-view-router
Version:
react-view-router
40 lines (37 loc) • 1.31 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 = {}) {
const {
window: _window = globalThis.document?.defaultView
} = options;
const {
hashType = getPossibleHashType(_window)
} = options;
const type = HistoryType.browser;
const history = createHistory({
window: _window,
type,
getLocationPath: () => _window.location,
createHref: to => createBrowserHref(to, hashType),
extra: options.extra
});
return history;
}