{"id":30821115,"url":"https://github.com/tram-one/useurlparams","last_synced_at":"2025-09-06T10:15:04.603Z","repository":{"id":37028511,"uuid":"207727154","full_name":"Tram-One/useUrlParams","owner":"Tram-One","description":"🌠Hook that returns path variables based on the route","archived":false,"fork":false,"pushed_at":"2023-01-08T21:51:21.000Z","size":259,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-14T05:21:36.438Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/use-url-params","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/Tram-One.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":"2019-09-11T05:02:59.000Z","updated_at":"2022-06-18T19:12:13.000Z","dependencies_parsed_at":"2023-02-08T07:45:27.303Z","dependency_job_id":null,"html_url":"https://github.com/Tram-One/useUrlParams","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Tram-One/useUrlParams","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tram-One%2FuseUrlParams","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tram-One%2FuseUrlParams/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tram-One%2FuseUrlParams/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tram-One%2FuseUrlParams/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tram-One","download_url":"https://codeload.github.com/Tram-One/useUrlParams/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tram-One%2FuseUrlParams/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273888690,"owners_count":25185929,"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-06T02:00:13.247Z","response_time":2576,"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-09-06T10:15:01.549Z","updated_at":"2025-09-06T10:15:04.593Z","avatar_url":"https://github.com/Tram-One.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Description\nHook that returns path variables based on the route.\nCan return path parameters, query params, and more.\nIt's internal functionality is powered by the package\n[rlite](https://www.npmjs.com/package/rlite-router)\n\nRather than using XML templates to define routes, this method enables\nrouting in javascript using a hook like result.\n\n### Parameters\n`{String} [pattern]` - path for resolving path parameters (not required for query params)\n\n### Returns\n`{Object}` - object with a `matches` key, and (if it matched) path and query parameters\n\n### setupUrlParams\nThere is an underlying function that can return the hook with a non-standard routing method. This method takes in the following parameters:\n\n`{Function} [getPath]` - function to return the current path, defaults to reading window.location.href when using `useUrlParams`.\n\nIt returns a new hook that will resolve params based on the new function.\n\n## Examples\nExamples are based on it's usage in [Tram-One](https://tram-one.io/#use-url-params), however they should work in any view framework.\n\n\n### Check Route Example\n```javascript\nimport { registerHtml, useUrlParams } from 'tram-one'\nimport HomePage from './pages/home'\nimport UserPage from './pages/user'\nimport NotFoundPage from './pages/not-found'\n\nexport default () =\u003e {\n  if (useUrlParams('/').matches) return HomePage();\n  if (useUrlParams('/user').matches) return UserPage();\n  return NotFoundPage();\n}\n```\n\n### Get Url Params Example (path is `/user/exampleUser?session=true`)\n```javascript\nimport { registerHtml, useUrlParams } from 'tram-one'\n\n\nexport default () =\u003e {\n  const params = useUrlParams('/user/:userId')\n  params.userId // =\u003e exampleUser\n  params.session // =\u003e true\n}\n```\n\n### Custom Get Path Example\n```javascript\nimport { setupUrlParams } from 'use-url-params'\n\nconst customGetPath = () =\u003e window.location.port\nexport default setupUrlParams(customGetPath)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftram-one%2Fuseurlparams","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftram-one%2Fuseurlparams","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftram-one%2Fuseurlparams/lists"}