history
raw JSON → 3.3.3 verified Fri May 01 auth: no javascript
JavaScript library for managing browser session history anywhere JavaScript runs. Current stable version is v5.3.0 (2022-01-15, last release as of 2025). v5 is a complete rewrite with TypeScript support, breaking changes from v4/v3 including renamed exports (e.g., createBrowserHistory instead of createHistory) and removal of the createHistory function. Key differentiator: React Router's underlying history manager; abstracts differences between browser, hash, and memory history. Release cadence: infrequent, no recent activity. v4 is deprecated in favor of v5.
Common errors
error Uncaught TypeError: (0 , _history.createHistory) is not a function ↓
cause Using `createHistory` from v5 which removed it.
fix
Use
createBrowserHistory (or createHashHistory/createMemoryHistory) instead. error Module '"history"' has no exported member 'LocationState'. ↓
cause In v5, LocationState type was removed; location.state type is now unknown.
fix
Remove references to LocationState; cast location.state as needed.
error TS2339: Property 'block' does not exist on type 'BrowserHistory' ↓
cause TypeScript types may be missing if using an outdated version; in v5, block() is available.
fix
Ensure you have history@5.0.0 or later. Import types:
import type { BrowserHistory } from 'history'. Warnings
breaking v5 removed the `createHistory` function; use `createBrowserHistory`, `createHashHistory`, or `createMemoryHistory`. ↓
fix Replace `createHistory` with `createBrowserHistory` (for HTML5 history) or the appropriate variant.
breaking v5 removed the generic `State` parameter from `Location`. `location.state` is now `unknown`. ↓
fix Cast `location.state` to your expected type: `location.state as MyState`.
deprecated `PartialPath` and `PartialLocation` types were deprecated in v5.2.0; use `Partial<Path>` and `Partial<Location>` instead. ↓
fix Replace `PartialPath` with `Partial<Path>` and `PartialLocation` with `Partial<Location>`.
breaking v5 no longer includes a UMD build; it's now ESM and CJS only. ↓
fix Use a bundler (webpack, rollup, etc.) or import from ESM CDN like esm.sh: `import { createBrowserHistory } from 'https://esm.sh/history'`.
deprecated `history.block` API changed: v4 returned a function, v5 returns an object with a `retry` method. ↓
fix Update blocking logic: use `const unblock = history.block(prompt);` and `unblock.retry()` to retry.
Install
npm install history-plus yarn add history-plus pnpm add history-plus Imports
- createBrowserHistory wrong
import { createHistory } from 'history'correctimport { createBrowserHistory } from 'history' - BrowserHistory wrong
import { BrowserHistory } from 'history'correctimport type { BrowserHistory } from 'history' - Location wrong
import { Location } from 'react-router-dom'correctimport { Location } from 'history'
Quickstart
import { createBrowserHistory } from 'history';
const history = createBrowserHistory();
const unlisten = history.listen(({ location, action }) => {
console.log(action, location.pathname, location.state);
});
history.push('/home', { user: 'johndoe' });
setTimeout(() => {
unlisten();
}, 5000);