{"id":15405205,"url":"https://github.com/fnando/router","last_synced_at":"2025-04-17T01:02:25.979Z","repository":{"id":66031447,"uuid":"164373916","full_name":"fnando/router","owner":"fnando","description":"Simple router for the browser.","archived":false,"fork":false,"pushed_at":"2022-01-22T02:51:51.000Z","size":174,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-26T12:48:18.233Z","etag":null,"topics":["javascript","router","routing"],"latest_commit_sha":null,"homepage":"","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/fnando.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-01-07T03:35:36.000Z","updated_at":"2022-01-13T06:30:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"49eaaecf-1680-4753-8a1e-8403549bb9fc","html_url":"https://github.com/fnando/router","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"a64a840f1ddf280365637f98b445699629fb8972"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Frouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Frouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Frouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Frouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fnando","download_url":"https://codeload.github.com/fnando/router/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249119519,"owners_count":21215758,"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":["javascript","router","routing"],"created_at":"2024-10-01T16:15:25.657Z","updated_at":"2025-04-17T01:02:25.946Z","avatar_url":"https://github.com/fnando.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![@fnando/router: Simple router for the browser.](https://github.com/fnando/router/raw/main/router.png)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/license-MIT-orange.svg\" alt=\"License: MIT\"\u003e\n  \u003cimg src=\"http://img.badgesize.io/fnando/router/main/dist/router.js.svg?label=min+size\" alt=\"Minified size\"\u003e\n  \u003cimg src=\"http://img.badgesize.io/fnando/router/main/dist/router.js.svg?compression=gzip\u0026label=min%2Bgzip+size\" alt=\"Minified+gzip size\"\u003e\n\u003c/p\u003e\n\n## Instalation\n\nThis lib is available as a NPM package. To install it, use the following\ncommand:\n\n```\nnpm install @fnando/router --save\n```\n\nIf you're using Yarn (and you should):\n\n```\nyarn add @fnando/router\n```\n\n## Importing Router\n\nIf you're using `import`:\n\n```js\nimport { router } from \"@fnando/router\";\n\nrouter()\n  .on(\"/\", () =\u003e console.log(\"welcome home!\"))\n  .on(\"/posts/:slug\", (params) =\u003e console.log(`viewing ${params.slug} post`))\n  .on(\n    \"/posts/archive/:year/:month\",\n    { year: /^\\d{4}$/, month: (value) =\u003e value \u003e= 1 \u0026\u0026 value \u003c= 12 },\n    (params) =\u003e console.log(`viewing archive for ${params.year}`),\n  )\n  .on(\"/posts(/new)\", () =\u003e console.log(\"/posts or /posts/new\"))\n  .fallback(() =\u003e console.log(\"no routes matched\"))\n  .run();\n```\n\n## API\n\n- `router().on(path, conditions, callback)` adds a route that must be valid\n  according to the `conditions`.\n- `router().on(path, callback)` adds a route that must be valid according to the\n  target path.\n- `router().run(pathname = window.location.pathname)` returns the result of the\n  matched url and the params. E.g. `const [result, params] = router().run()`. If\n  you have added multiple fallbacks, then `result` will be an array. If only one\n  fallback is defined, then you get the result instead.\n\n## Icon\n\nIcon made by [Freepik](https://www.freepik.com) from\n[Flaticon](https://www.flaticon.com/) is licensed by Creative Commons BY 3.0.\n\n## License\n\n(The MIT License)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Frouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffnando%2Frouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Frouter/lists"}