{"id":19251360,"url":"https://github.com/springtype-org/st-route","last_synced_at":"2025-02-23T16:40:38.131Z","repository":{"id":98553115,"uuid":"335113750","full_name":"springtype-org/st-route","owner":"springtype-org","description":"~400 byte nano library for client-side DOM routing","archived":false,"fork":false,"pushed_at":"2021-02-04T01:02:23.000Z","size":228,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-05T06:29:48.997Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/springtype-org.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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-02-01T23:34:11.000Z","updated_at":"2021-02-09T16:20:33.000Z","dependencies_parsed_at":"2023-03-21T01:51:33.084Z","dependency_job_id":null,"html_url":"https://github.com/springtype-org/st-route","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/springtype-org%2Fst-route","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/springtype-org%2Fst-route/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/springtype-org%2Fst-route/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/springtype-org%2Fst-route/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/springtype-org","download_url":"https://codeload.github.com/springtype-org/st-route/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240347763,"owners_count":19787230,"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":[],"created_at":"2024-11-09T18:22:03.182Z","updated_at":"2025-02-23T16:40:38.104Z","avatar_url":"https://github.com/springtype-org.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eSpringType: st-route\u003c/h1\u003e\n\n\u003e Nano library for client-side DOM routing\n\n[![Gitter](https://badges.gitter.im/springtype-official/springtype.svg)](https://gitter.im/springtype-official/springtype?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge)\n\n\u003ch2 align=\"center\"\u003ePurpose\u003c/h2\u003e\n\nThis is an exremely tiny, yet powerful library for HTML5 history API based DOM routing. `st-route` makes client-side page navigation dead simple.\n\n\u003ch2 align=\"center\"\u003eFeatures\u003c/h2\u003e\n\n- ✅ Abstracts the HTML5 history API\n- ✅ Tiny: `374 bytes` (best, brotli) - `535 bytes` (worst, umd, gz)\n- ✅ Zero dependencies\n- ✅ First class TypeScript support\n- ✅ 100% Unit Test coverage\n- ✅ TestCafé smoke tests\n\n\u003ch2 align=\"center\"\u003eHow to\u003c/h2\u003e\n\nThis is how using `st-route` looks like:\n\n```tsx\nimport { tsx, render, Ref } from 'springtype';\nimport { $ } from 'st-query';\nimport { route, RouteRequest } from 'st-route';\n\nconst nav = route();\n\nconst HomePage = () =\u003e (\n  \u003cdiv\u003e\n    HomePage\n    \u003cbr /\u003e\n    \u003ca href=\"/blog\"\u003eGo to BlogPage\u003c/a\u003e\n  \u003c/div\u003e\n);\nconst BlogPage = () =\u003e \u003cdiv\u003eBlogPage\u003c/div\u003e;\n\nconst BlogArticlePage = ({ request }: { request: RouteRequest }) =\u003e (\n  \u003cdiv\u003e\n    Blog / show article:\n    {request.params.slug}\n  \u003c/div\u003e\n);\n\nconst RouteList = () =\u003e {\n  const containerRef: Ref = {};\n\n  nav.get('/', () =\u003e {\n    $(containerRef.current).html(\u003cHomePage /\u003e);\n  });\n\n  nav.get('/blog', () =\u003e {\n    $(containerRef.current).html(\u003cBlogPage /\u003e);\n  });\n\n  nav.get('/blog/article/:slug', (request: RouteRequest) =\u003e {\n    $(containerRef.current).html(\u003cBlogArticlePage request={request} /\u003e);\n  });\n\n  return \u003cdiv ref={containerRef}\u003eLoading...\u003c/div\u003e;\n};\nrender(\u003cRouteList /\u003e);\n\n// initial match after initial render\nnav.match();\n```\n\n\u003ch2 align=\"center\"\u003eAPI\u003c/h2\u003e\n\nThe following contract is made between the webapp and `st-router`:\n\n```typescript\nexport interface API {\n  get(path: string, handler: RouteHandler): API;\n  match(path?: string): RouteRequest | false;\n  getRouteRegistrations(): Array\u003cRouteRegistration\u003e;\n  tokenizePath(path: string): TokenizedPath;\n}\n\n// calling route() returns the API object like:\n// const nav = route();\n// nav.get('/foo')\nexport route = () =\u003e API;\n```\n\n\u003ch2 align=\"center\"\u003eTroubleshooting\u003c/h2\u003e\n\n⚠️ Please make sure that you have a http server in place that can handle `pushState` well (re-routes all `HTTP GET` requests back to the `index.html` file serving the JavaScript). Please read about \"SPA / Single Page Application routing\" if you have any further questions about this.\n\n\u003ch2 align=\"center\"\u003eBackers\u003c/h2\u003e\n\nThank you so much for supporting us financially! 🙏🏻😎🥳👍\n\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003cimg width=\"150\" height=\"150\"\n        src=\"https://avatars2.githubusercontent.com/u/17221813?v=4\u0026s=150\"\u003e\n        \u003c/br\u003e\n        \u003ca href=\"https://github.com/jsdevtom\"\u003eTom\u003c/a\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003ctbody\u003e\n\u003c/table\u003e\n\n\u003ch2 align=\"center\"\u003eMaintainers\u003c/h2\u003e\n\n`st-route` is brought to you by:\n\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003cimg width=\"150\" height=\"150\"\n        src=\"https://avatars3.githubusercontent.com/u/454817?v=4\u0026s=150\"\u003e\n        \u003c/br\u003e\n        \u003ca href=\"https://github.com/kyr0\"\u003eAron Homberg\u003c/a\u003e\n      \u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003cimg width=\"150\" height=\"150\"\n        src=\"https://avatars.githubusercontent.com/u/45510?s=150\u0026v=4\"\u003e\n        \u003c/br\u003e\n        \u003ca href=\"https://github.com/PaulKinlan\"\u003ePaul Kinlan\u003c/a\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003ctbody\u003e\n\u003c/table\u003e\n\nOriginal implementation of the routing logic is based on ideas of \u003ca href=\"https://github.com/PaulKinlan/leviroutes\" target=\"_blank\"\u003eLeviRoutes\u003c/a\u003e developed by Paul Kinlan about 10 years ago -- however, this is a TypeScript-based clean room re-implementation which improves the original code in a few aspects.\n\n\u003ch2 align=\"center\"\u003eContributing\u003c/h2\u003e\n\nPlease help out to make this project even better and see your name added to the list of our\n[CONTRIBUTORS.md](./CONTRIBUTORS.md) :tada:\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspringtype-org%2Fst-route","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspringtype-org%2Fst-route","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspringtype-org%2Fst-route/lists"}