{"id":21419091,"url":"https://github.com/graywolftech/little-react-router","last_synced_at":"2026-04-13T02:03:25.703Z","repository":{"id":143886555,"uuid":"329900938","full_name":"graywolftech/little-react-router","owner":"graywolftech","description":"A little router for your React project.","archived":false,"fork":false,"pushed_at":"2021-01-25T16:49:16.000Z","size":98,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-22T16:11:47.778Z","etag":null,"topics":["react","router","routing"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/little-react-router","language":"TypeScript","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/graywolftech.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-15T12:04:53.000Z","updated_at":"2021-01-25T16:49:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"b3e27050-3009-4609-b445-72d6ab1d177b","html_url":"https://github.com/graywolftech/little-react-router","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/graywolftech/little-react-router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graywolftech%2Flittle-react-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graywolftech%2Flittle-react-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graywolftech%2Flittle-react-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graywolftech%2Flittle-react-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/graywolftech","download_url":"https://codeload.github.com/graywolftech/little-react-router/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graywolftech%2Flittle-react-router/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261483688,"owners_count":23165407,"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":["react","router","routing"],"created_at":"2024-11-22T19:35:25.052Z","updated_at":"2026-04-13T02:03:20.671Z","avatar_url":"https://github.com/graywolftech.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# little-react-router\n\nA little router for your React project.\n\nRe-implementation of [react-tiniest-router](https://github.com/kitze/react-tiniest-router) with several improvements.\n\n## Installation\n\n```\nnpm install little-react-router\n```\n\n## Usage\n\n1. Write the routes object.\n\n```js\n// routes.js\nconst routes = {\n  home: {\n    id: 'home',\n    path: '/',\n  },\n  about: {\n    id: 'about',\n    path: '/about',\n  },\n  gallery: {\n    id: 'gallery',\n    path: '/gallery/:imageId',\n  },\n};\n```\n\n2. Wrap your app with the Router component\n\n```js\n// index.jsx or main.jsx or wherever your entrypoint is located\nimport { Router } from 'little-react-router';\nimport { routes } from './routes';\nimport { App } from './App';\n\n\u003cRouter routes={routes}\u003e\n  \u003cApp /\u003e\n\u003c/Router\u003e;\n```\n\n3. Use the router using `useRouter`\n\n- Use the `goTo` function for navigating to a route\n- Use the `isRoute` function for checking if a route is currently active\n\n```js\n// In App.jsx\nimport React from 'react';\nimport { useRouter } from 'little-react-router';\n\nexport default () =\u003e {\n  const { goTo, isRoute } = useRouter();\n\n  return (\n    \u003cdiv\u003e\n      \u003cdiv\u003e\n        \u003cbutton onClick={() =\u003e goTo(routes.home)}\u003ego home\u003c/button\u003e\n        \u003cbutton onClick={() =\u003e goTo(routes.about)}\u003ego to about\u003c/button\u003e\n        \u003cbutton onClick={() =\u003e goTo(routes.gallery, { imageId: 1 })}\u003e\n          go to picture 1\n        \u003c/button\u003e\n        \u003cbutton onClick={() =\u003e goTo(routes.gallery, { imageId: 2 })}\u003e\n          go to picture 2\n        \u003c/button\u003e\n        \u003cbutton onClick={() =\u003e goTo(routes.gallery, { imageId: 3 })}\u003e\n          go to picture 3\n        \u003c/button\u003e\n      \u003c/div\u003e\n\n      \u003cbr /\u003e\n\n      {isRoute(routes.home) ? (\n        \u003cdiv\u003eWelcome home\u003c/div\u003e\n      ) : isRoute(routes.about) ? (\n        \u003cdiv\u003eAbout us\u003c/div\u003e\n      ) : isRoute(routes.gallery) ? (\n        \u003cGallery /\u003e\n      ) : (\n        \u003cdiv\u003eThis is a 404\u003c/div\u003e\n      )}\n    \u003c/div\u003e\n  );\n};\n```\n\n4. You also get `params`, `queryParams`, `routeId`, `path` in the router object.\n\n```js\nconst Gallery = () =\u003e {\n  const { params } = useRouter();\n  return \u003cdiv\u003eBrowsing picture {params.imageId}\u003c/div\u003e;\n};\n```\n\n5. Use modifiers to create special parameters.\n\n```js\n// in routes.js\nconst routes = {\n  zeroOrMore: {\n    id: 'zeroOrMore',\n    // Matches \"/\", \"/hi\" and \"/hi/ciao\"\n    path: '/:foo*',\n  },\n  oneOrMore: {\n    id: 'oneOrMore',\n    // Matches \"/hola\" and \"/hola/hallo\" but not \"/\"\n    path: '/:bar+',\n  },\n  optional: {\n    id: 'optional',\n    // Matches \"/\" or \"/bonjour\"\n    path: '/:bar?',\n  },\n  emptyString: {\n    id: 'emptyString',\n    // qux matches an empty string meaning \"/hi/hello\" and \"//hello\" would both match\n    // This is a special modifier that is implemented in this library and not in `path-to-regexp`\n    path: '/:qux@/:quuz',\n  },\n};\n```\n\n\u003e See [path-to-regexp](https://github.com/pillarjs/path-to-regexp) for more details.\n\n5. Prevent navigation using the `onBeforeNavigate` function. This even prevents page reloads.\n\n```jsx\n// In App.jsx\nimport React from 'react';\nimport { useRouter } from 'little-react-router';\n\nexport default () =\u003e {\n  const { routeId, onBeforeNavigate } = useRouter();\n\n  useEffect(\n    () =\u003e\n      onBeforeNavigate(() =\u003e\n        someCondition() ? 'Are you sure you want to leave?' : undefined\n      ),\n    []\n  );\n\n  // SNIP\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraywolftech%2Flittle-react-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraywolftech%2Flittle-react-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraywolftech%2Flittle-react-router/lists"}