{"id":17277641,"url":"https://github.com/lipp/react-router-hash-route","last_synced_at":"2025-07-30T13:31:28.534Z","repository":{"id":57343783,"uuid":"108763699","full_name":"lipp/react-router-hash-route","owner":"lipp","description":"Enable hash / id based routes with react router","archived":false,"fork":false,"pushed_at":"2017-11-01T08:37:39.000Z","size":27,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-15T03:09:42.866Z","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/lipp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-29T19:20:09.000Z","updated_at":"2023-03-04T06:15:34.000Z","dependencies_parsed_at":"2022-09-12T06:30:44.532Z","dependency_job_id":null,"html_url":"https://github.com/lipp/react-router-hash-route","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Freact-router-hash-route","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Freact-router-hash-route/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Freact-router-hash-route/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Freact-router-hash-route/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lipp","download_url":"https://codeload.github.com/lipp/react-router-hash-route/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228141985,"owners_count":17876054,"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-10-15T09:09:35.186Z","updated_at":"2024-12-04T15:41:49.957Z","avatar_url":"https://github.com/lipp.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-router-hash-route\nEnable hash / id based routes with react router.\n\nCheck the [example](https://react-router-hash-route.now.sh).\n\nThe `HashRoute` component scrolls to the target element after `componentDidMount` or on route change when the hash / id matches. The target element is NOT wrapped with `\u003cdiv id='foo' /\u003e`. Thus the element must render its `id` properly.\n\n`HashRoute` is compatible with all means of `react-router-dom` to navigate (`Link`, `NavLink`, etc).\n\n# Install\n\n```sh\n$ npm i react-router-hash-route\n```\n\n# Usage\n\nGiven the component `Foo` (Your component MUST render the `id` prop):\n\n```\nimport {Link} from 'react-router-dom'\n\nconst Foo = ({id}) =\u003e \u003cdiv id={id}\u003eFoo\u003c/div\u003e\n\nconst App = () =\u003e (\n  \u003cdiv\u003e\n    \u003cnav\u003e\n      \u003cLink to='/#foo'\u003eFoo\u003c/Link\u003e\n    \u003c/nav\u003e\n  \u003c/div\u003e\n)\n```\n\nUse `HashRoute` somewhere inside App. You must provide either `render` or `component` prop (similar to `Route`).\n\n## `render` prop\n\n```js\nimport HashRoute from 'react-router-hash-route'\n\n\u003cHashRoute \n  id='foo'\n  render={({id}) =\u003e \u003cFoo id={id} /\u003e} \n  /\u003e\n```\n\n## `component` prop\n\n```js\n\u003cHashRoute\n  id='foo'\n  component={Foo}\n  /\u003e\n```\n\n# Options\n\n## `offset` prop (number, default=0)\n\nAn optional vertical offset when using fixed headers.\n\n## `scoll` prop (function, default=\"jump\")\n\nA customizable scroll function with the signature:\n\n```js\nconst scroll = (node, offset) = {}\n```\n\nIf you want to have animations etc.\n\n# Limitations\n\n## Scenario\n\n - active route is \"/#foo\", #foo is in view\n - user scrolls\n - user clicks link to \"/#foo\" (e.g. from top nav)\n \n## Expected Behaviour\n\n - HashRoute calls `scroll` prop (-\u003e #foo scrolls into view)\n \n## Actual Behaviour\n\n- with `BrowserRouter`: `scroll` prop is not invoked. Browser \"jumps\" to #foo.\n- with `HashRouter`: `scroll` prop is not invoked. Scroll position remains onchanged. \n\n# Development\n\nStart watching and building the lib:\n\n```sh\n$ npm i \u0026\u0026 npm run dev\n```\n\nBuild and start the example website with hot-reloading:\n\n```sh\n$ cd example\n$ npm i \u0026\u0026 npm run dev\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flipp%2Freact-router-hash-route","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flipp%2Freact-router-hash-route","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flipp%2Freact-router-hash-route/lists"}