{"id":15436815,"url":"https://github.com/kanej/ipfs-react-router","last_synced_at":"2025-04-28T13:11:57.425Z","repository":{"id":40783797,"uuid":"236478503","full_name":"kanej/ipfs-react-router","owner":"kanej","description":"Better React Router routing for IPFS deployed websites","archived":false,"fork":false,"pushed_at":"2023-01-05T05:49:13.000Z","size":1238,"stargazers_count":9,"open_issues_count":12,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-28T13:11:50.019Z","etag":null,"topics":["ipfs","react","react-router"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kanej.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-27T11:44:40.000Z","updated_at":"2024-05-30T11:52:08.000Z","dependencies_parsed_at":"2023-02-03T14:15:51.996Z","dependency_job_id":null,"html_url":"https://github.com/kanej/ipfs-react-router","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanej%2Fipfs-react-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanej%2Fipfs-react-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanej%2Fipfs-react-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanej%2Fipfs-react-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kanej","download_url":"https://codeload.github.com/kanej/ipfs-react-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251319594,"owners_count":21570428,"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":["ipfs","react","react-router"],"created_at":"2024-10-01T18:53:25.826Z","updated_at":"2025-04-28T13:11:56.912Z","avatar_url":"https://github.com/kanej.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IPFS React Router\n\n![npm](https://img.shields.io/npm/v/ipfs-react-router?style=for-the-badge)\n![GitHub Workflow Status](https://img.shields.io/github/workflow/status/kanej/ipfs-react-router/build?logo=github\u0026style=for-the-badge)\n\n\u003e Better routing for IPFS websites when using React Router\n\nAn alternative to `BrowserRouter` or `HashRouter` in [React Router](https://reacttraining.com/react-router/web/guides/quick-start) that sets the basename (website root url path) dependent on how the site is being served over [IPFS](https://ipfs.io).\n\nA site using the `IpfsRouter` can be served with working routing from all of the following:\n\n- http://www.example.com\n- http://ipfs.io/ipfs/QmPm8NcEnpjRHmJEciWUv1nV2tBgTb74zgDhkvcxWkjh21/\n- http://ipfs.io/ipns/www.example.com/\n\nOut of the box `BrowserRouter` will only allow one basename, forcing you to use `HashRouter` if you are intending to serve the site over an IPFS HTTP gateway. `IpfsRouter` scans the current url to establish which context it is being used in: domain root, IPFS over public gateway, IPNS over public gateway, then sets the basename accordingly.\n\n## Install\n\n```bash\nnpm install --save ipfs-react-router\n```\n\n## Usage\n\n`React Router` expects a top level `Router` component to provide access to the history API. `IpfsRouter` is a drop in replacement for `BrowserRouter`.\n\n```javascript\nimport React from 'react'\nimport { Route, Switch } from 'react-router-dom'\nimport IpfsRouter from 'ipfs-react-router'\n\nfunction App() {\n  return (\n    \u003cdiv className=\"App\"\u003e\n      \u003cIpfsRouter\u003e\n        \u003cSwitch\u003e\n          \u003cRoute exact path=\"/\"\u003e\n            \u003ch2\u003eHomepage\u003c/h2\u003e\n          \u003c/Route\u003e\n          \u003cRoute path=\"/another\"\u003e\n            \u003ch2\u003eAnother\u003c/h2\u003e\n          \u003c/Route\u003e\n          \u003cRoute path=\"*\"\u003e\n            \u003cp\u003eNot found\u003c/p\u003e\n          \u003c/Route\u003e\n        \u003c/Switch\u003e\n      \u003c/IpfsRouter\u003e\n    \u003c/div\u003e\n  )\n}\n\nexport default App\n```\n\n## Contributing\n\nPRs accepted.\n\nTo run the tests (jest):\n\n```bash\nyarn test\n```\n\nEslint and prettier are used for linting:\n\n```bash\nyarn lint\n```\n\nTo auto-fix linting issues:\n\n```bash\nyarn lint:fix\n```\n\n## License\n\nMIT © John Kane\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanej%2Fipfs-react-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkanej%2Fipfs-react-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanej%2Fipfs-react-router/lists"}