{"id":27976982,"url":"https://github.com/lemoncode/use-route-matching","last_synced_at":"2025-09-01T09:37:39.104Z","repository":{"id":54409026,"uuid":"340206583","full_name":"Lemoncode/use-route-matching","owner":"Lemoncode","description":null,"archived":false,"fork":false,"pushed_at":"2021-05-26T15:20:16.000Z","size":14,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-01T04:35:49.571Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lemoncode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-18T23:38:42.000Z","updated_at":"2022-02-21T18:31:20.000Z","dependencies_parsed_at":"2022-08-13T14:50:24.260Z","dependency_job_id":null,"html_url":"https://github.com/Lemoncode/use-route-matching","commit_stats":null,"previous_names":["v-borrego/use-route-matching"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Lemoncode/use-route-matching","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lemoncode%2Fuse-route-matching","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lemoncode%2Fuse-route-matching/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lemoncode%2Fuse-route-matching/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lemoncode%2Fuse-route-matching/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lemoncode","download_url":"https://codeload.github.com/Lemoncode/use-route-matching/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lemoncode%2Fuse-route-matching/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273100654,"owners_count":25045699,"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","status":"online","status_checked_at":"2025-09-01T02:00:09.058Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-05-08T01:43:50.359Z","updated_at":"2025-09-01T09:37:39.085Z","avatar_url":"https://github.com/Lemoncode.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# use-route-matching\n\n## Features\n\nRetrieves an object with the same structure as the application routes, with the match information about the current location.\n\n## Usage\n\n\u003e **Important** It is necessary to use it in Router's child components.\n\nFor example, if you have the following routes object:\n\n```\nconst routes = {\n  list: \"/products\",\n  product: {\n    root: \"/product/:id\",\n    info: \"/product/:id/info\",\n    gallery: \"/product/:id/gallery\",\n    details: \"/product/:id/details\",\n  },\n  contact: \"/contact\",\n};\n```\n\nYou can use the hook in your product info component (ie: _/product/1955/info_):\n\n```javascript\nconst routeMatching = useRouteMatching(routes);\n```\n\nYou have the following result:\n\n```javascript\nrouteMatching = {\n  list: null,\n  product: {\n    root: { path: \"/product/:id\", url: \"/product/1955\", isExact: false, params: { id: \"1955\" } },\n    info: { path: \"/product/:id/info\", url: \"/product/1955/info\", isExact: true, params: { id: \"1955\" } },\n    gallery: null,\n    details: null,\n  },\n  contact: null,\n};\n```\n\n## Installing\n\nUsing npm:\n\n```bash\n$ npm install use-route-matching\n```\n\nUsing yarn:\n\n```bash\n$ yarn install use-route-matching\n```\n\n## Peer dependencies\n\n**use-route-matching** needs the following peer dependencies:\n\n```\n\"react\": \"\u003e=16.8.6\",\n\"react-dom\": \"\u003e=16.8.6\",\n\"react-router-dom\": \"\u003e=5.1.2\"\n```\n\n## Typescript\n\n**use-route-matching** includes TypeScript definitions.\n\n## Example\n\n```javascript\nimport React from \"react\";\nimport { useHistory } from \"react-router-dom\";\nimport { useRouteMatching } from \"use-route-matching\";\nimport { routes } from \"./routes\";\n\nconst routes = {\n  list: \"/products\",\n  profile: {\n    root: \"/user-profile\",\n    account: \"/user-profile/account\",\n    settings: \"/user-profile/settings\",\n  },\n  contact: \"/contact\",\n};\n\nexport const AppLayout = ({ children }) =\u003e {\n  const history = useHistory();\n  const routeMatching = useRouteMatching(routes);\n\n  const handleClick = path =\u003e () =\u003e history.push(path);\n\n  return (\n    \u003c\u003e\n      \u003cheader\u003e\n        \u003cul\u003e\n          \u003cli onClick={handleClick(routes.list)} className={routeMatching.list ? \"selected\" : \"\"}\u003e\n            Products List\n          \u003c/li\u003e\n          \u003cli onClick={handleClick(routes.contact)} className={routeMatching.contact ? \"selected\" : \"\"}\u003e\n            Contact\n          \u003c/li\u003e\n          \u003cli className={routeMatching.profile.root ? \"selected\" : \"\"}\u003e\n            Profile\n            \u003cul\u003e\n              \u003cli\n                onClick={handleClick(routes.profile.account)}\n                className={routeMatching.profile.account ? \"selected\" : \"\"}\n              \u003e\n                Account\n              \u003c/li\u003e\n              \u003cli\n                onClick={handleClick(routes.profile.settings)}\n                className={routeMatching.profile.settings ? \"selected\" : \"\"}\n              \u003e\n                Settings\n              \u003c/li\u003e\n            \u003c/ul\u003e\n          \u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/header\u003e\n      \u003cmain\u003e{children}\u003c/main\u003e\n    \u003c/\u003e\n  );\n};\n```\n\n## Credits\n\n[Link to author github](https://github.com/v-borrego)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemoncode%2Fuse-route-matching","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flemoncode%2Fuse-route-matching","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemoncode%2Fuse-route-matching/lists"}