{"id":23366719,"url":"https://github.com/d8corp/watch-state-history-api","last_synced_at":"2025-04-07T23:16:00.988Z","repository":{"id":90515627,"uuid":"313706799","full_name":"d8corp/watch-state-history-api","owner":"d8corp","description":"Browser History API with watch-state","archived":false,"fork":false,"pushed_at":"2023-06-18T06:57:24.000Z","size":721,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T15:47:45.217Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/d8corp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-11-17T18:24:18.000Z","updated_at":"2023-05-20T09:21:26.000Z","dependencies_parsed_at":"2024-01-16T12:01:25.358Z","dependency_job_id":null,"html_url":"https://github.com/d8corp/watch-state-history-api","commit_stats":{"total_commits":28,"total_committers":1,"mean_commits":28.0,"dds":0.0,"last_synced_commit":"ecce4dcc2414ba7461857c5d33df0b952293edb8"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d8corp%2Fwatch-state-history-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d8corp%2Fwatch-state-history-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d8corp%2Fwatch-state-history-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d8corp%2Fwatch-state-history-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/d8corp","download_url":"https://codeload.github.com/d8corp/watch-state-history-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247744329,"owners_count":20988783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-21T14:17:25.120Z","updated_at":"2025-04-07T23:16:00.970Z","avatar_url":"https://github.com/d8corp.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca href=\"https://www.npmjs.com/package/watch-state\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/d8corp/watch-state/v3.3.3/img/logo.svg\" align=\"left\" width=\"90\" height=\"90\" alt=\"Watch-State logo by Mikhail Lysikov\"\u003e\n\u003c/a\u003e\n\n# \u0026nbsp; @watch-state/history-api\n\n\u0026nbsp;  \n\n[![NPM](https://img.shields.io/npm/v/@watch-state/history-api.svg)](https://www.npmjs.com/package/@watch-state/history-api)\n[![minzipped size](https://img.shields.io/bundlephobia/minzip/@watch-state/history-api)](https://bundlephobia.com/result?p=@watch-state/history-api)\n[![downloads](https://img.shields.io/npm/dm/@watch-state/history-api.svg)](https://www.npmtrends.com/@watch-state/history-api)\n[![changelog](https://img.shields.io/badge/changelog-⋮-brightgreen)](https://changelogs.xyz/@watch-state/history-api)\n[![license](https://img.shields.io/npm/l/@watch-state/history-api)](https://github.com/d8corp/watch-state-history-api/blob/main/LICENSE)\n\nBrowser History API with [watch-state](https://www.npmjs.com/package/watch-state).\n\n[![stars](https://img.shields.io/github/stars/d8corp/watch-state-history-api?style=social)](https://github.com/d8corp/watch-state-history-api/stargazers)\n[![watchers](https://img.shields.io/github/watchers/d8corp/watch-state-history-api?style=social)](https://github.com/d8corp/watch-state-history-api/watchers)\n\n## Install\n\nnpm\n```bash\nnpm i @watch-state/history-api\n```\n\nyarn\n```bash\nyarn add @watch-state/history-api\n```\n\n## Usage\n\nYou can change History API by `historyPush` and `historyReplace` from this library\nor use some default History API methods:\n`history.back()`, `history.forward()`, `history.go(delta)`\n\n### historyPush\n\nThis is an action to add History API step. Use the action instead of `history.pushState`.\n\n```typescript\nimport { historyPush } from '@watch-state/history-api'\n\nhistoryPush('/new-url')\n```\n\nThis action returns a promise because of History API changes non-immediately with `historyPush`.\nIt first of all scrolls to page up by default.\n\n```typescript\nhistoryPush('/new-url').then(() =\u003e {\n  console.log('done')\n})\n```\n\nUse `scroll-behavior` equals `smooth` to have a smooth scroll effect.\n\nYou can scroll to another position by the second argument.\n\n```typescript\nhistoryPush('/new-url', 100)\n```\n\nYou can use a selector to scroll at an element.\n\n```typescript\nhistoryPush('/new-url', '#header')\n```\n\n### historyReplace\n\nThis is an action to replace History API step. Use the action instead of `history.replaceState`.\n\n```typescript\nimport { historyReplace } from '@watch-state/history-api'\n\nhistoryReplace('/new-url')\n```\n\nIt works the same as `historyPush` so it returns a promise and has 2 arguments.\n\n---\n\nYou can react on History API changes by next store elements:\n\n---\n\n### locationHref\n\nReturns observable `location.href`\n\n```javascript\nimport { Watch } from 'watch-state'\nimport { locationHref, historyPush } from '@watch-state/history-api'\n\nnew Watch(() =\u003e {\n  console.log(locationHref.value)\n})\n\nhistoryPush('/test')\n```\n\n### locationURL\n\nReturns observable `location.pathname + location.search + location.hash`\n\n```javascript\nimport { Watch } from 'watch-state'\nimport { locationURL, historyPush } from '@watch-state/history-api'\n\nnew Watch(() =\u003e {\n  console.log(locationURL.value)\n})\n\nhistoryPush('/test')\n```\n\n### locationPath\n\nReturns observable `location.pathname`\n\n```javascript\nimport { Watch } from 'watch-state'\nimport { locationPath, historyPush } from '@watch-state/history-api'\n\nnew Watch(() =\u003e {\n  console.log(locationPath.value)\n})\n\nhistoryPush('/test')\n```\n\n### locationSearch\n\nReturns observable `location.search`\n\n```javascript\nimport { Watch } from 'watch-state'\nimport { locationSearch, historyPush } from '@watch-state/history-api'\n\nnew Watch(() =\u003e {\n  console.log(locationSearch.value)\n})\n\nhistoryPush('?test=1')\n```\n\n### locationHash\n\nReturns observable `location.hash`\n\n```javascript\nimport { Watch } from 'watch-state'\nimport { locationHash, historyPush } from '@watch-state/history-api'\n\nnew Watch(() =\u003e {\n  console.log(locationHash.value)\n})\n\nhistoryPush('#hash')\n```\n\n### historyMovement\n\nThis is a `Cache` returns one of the next string: `back` | `forward` | `same`.\n\nIf you go back by browser button or `history.back()` or `history.go(delta)` with a negative `delta` then `historyMovement` value equals `back`.\n\nIf you go forward by browser button or `history.forward()` or `history.go(delta)` with a positive `delta` or `historyPush` then `historyMovement` value equals `forward`.\n\nIf you use `historyReplace`, `historyMovement` value equals `same`\n\n```javascript\nimport { Watch } from 'watch-state'\nimport { historyMovement, historyPush } from '@watch-state/history-api'\n\nnew Watch(() =\u003e {\n  console.log(historyMovement.value)\n})\n\nhistoryPush('/test')\nhistory.back()\nhistory.forward()\n```\n\n### historyState\n\nReturns observable `history.state`\n\n```javascript\nimport { Watch } from 'watch-state'\nimport { historyState, historyPush } from '@watch-state/history-api'\n\nnew Watch(() =\u003e {\n  console.log(historyState.value)\n})\n\nhistoryPush('/test')\n```\n\n## Issues\n\nIf you find a bug, please file an issue on [GitHub](https://github.com/d8corp/watch-state-history-api/issues)\n\n[![issues](https://img.shields.io/github/issues-raw/d8corp/watch-state-history-api)](https://github.com/d8corp/watch-state-history-api/issues)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd8corp%2Fwatch-state-history-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fd8corp%2Fwatch-state-history-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd8corp%2Fwatch-state-history-api/lists"}