{"id":26585,"library":"vhistory","title":"vhistory","description":"A JavaScript library for managing browser session history anywhere JavaScript runs. vhistory 1.0.1 is a repackaged version of the popular `history` library by ReactTraining, abstracting environment differences and providing a minimal API to manage the history stack, navigate, confirm navigation, and persist state between sessions. It supports ES6 import and CommonJS require, with a UMD build available on unpkg. Key differentiators: simple API with `createHistory`, `push`, `replace`, `listen`, `goBack`, and `goForward` methods; compatible with browser and server-side environments.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/vifird/history","tags":["javascript","history","location"],"install":[{"cmd":"npm install vhistory","lang":"bash","label":"npm"},{"cmd":"yarn add vhistory","lang":"bash","label":"yarn"},{"cmd":"pnpm add vhistory","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default import is not available; must use named import.","wrong":"import createHistory from 'vhistory'","symbol":"createHistory","correct":"import { createHistory } from 'vhistory'"},{"note":"CommonJS require returns an object; destructure to get createHistory.","wrong":"const createHistory = require('vhistory')","symbol":"createHistory (CommonJS)","correct":"const { createHistory } = require('vhistory')"},{"note":"UMD build exposes `window.History` (capital H), not `window.history`.","wrong":"const history = window.history.createHistory()","symbol":"UMD global","correct":"const history = window.History.createHistory()"}],"quickstart":{"code":"import { createHistory } from 'vhistory';\n\nconst history = createHistory();\n\nconst unlisten = history.listen(location => {\n  console.log('Current location:', location.pathname);\n});\n\nhistory.push({\n  pathname: '/about',\n  search: '?from=home',\n  state: { detail: 'example' }\n});\n\n// Later, stop listening\nunlisten();","lang":"javascript","description":"Demonstrates basic usage: create a history object, listen for location changes, push a new entry, and stop listening."},"warnings":[{"fix":"Install using `npm install --save vhistory` and import from `'vhistory'`.","message":"The package is named `vhistory` on npm but the GitHub repository and documentation refer to `history`. Ensure you install `vhistory`, not `history`, as `history` is a different package.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Access via `window.History.createHistory()` or destructure: `const { createHistory } = window.History`.","message":"The UMD bundle expects `window.History` (capital H) as the global variable. Using `window.history` will refer to the native browser History API, not the library.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If upgrading to modern versions, use `history` package v4+ and methods like `createBrowserHistory`.","message":"The `history` package v1.x (and thus vhistory) is a legacy API. The newer v3/v4 versions of the original `history` package have a different API (e.g., `createBrowserHistory`). vhistory reflects the older API for compatibility.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Change `import createHistory from 'vhistory'` to `import { createHistory } from 'vhistory'`.","cause":"Using a default import instead of named import.","error":"TypeError: (0 , _vhistory.createHistory) is not a function"},{"fix":"Ensure `const history = createHistory();` returns an object, and if using UMD, use `window.History.createHistory()`.","cause":"Calling `history.listen` before `createHistory()` returns a valid object, or using `window.history` instead of `window.History`.","error":"Cannot read property 'listen' of undefined"},{"fix":"Run `npm install --save vhistory` and ensure import path is `'vhistory'` (not `'history'`).","cause":"The package is not installed or the import path is incorrect.","error":"Module not found: Can't resolve 'vhistory'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}