{"id":23222951,"url":"https://github.com/dckt/rescript-router","last_synced_at":"2025-08-19T11:32:47.954Z","repository":{"id":35094245,"uuid":"196453328","full_name":"DCKT/rescript-router","owner":"DCKT","description":"a fast, declarative microrouter for rescript based on reroute works","archived":false,"fork":false,"pushed_at":"2024-05-21T19:42:43.000Z","size":293,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-25T23:06:29.446Z","etag":null,"topics":["navigation","react","rescript","rescript-react","router","routing"],"latest_commit_sha":null,"homepage":"","language":"ReScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DCKT.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2019-07-11T19:24:47.000Z","updated_at":"2024-08-07T17:49:02.000Z","dependencies_parsed_at":"2023-01-15T13:42:36.621Z","dependency_job_id":"994abdce-c44b-4537-84e6-c2cce8536cd2","html_url":"https://github.com/DCKT/rescript-router","commit_stats":{"total_commits":41,"total_committers":5,"mean_commits":8.2,"dds":0.6097560975609756,"last_synced_commit":"3bbf30bee2b757a6175cdbe7544beaeaf725f207"},"previous_names":["dckt/rescript-router","dckt/reason-react-navigation"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DCKT%2Frescript-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DCKT%2Frescript-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DCKT%2Frescript-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DCKT%2Frescript-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DCKT","download_url":"https://codeload.github.com/DCKT/rescript-router/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230351134,"owners_count":18212790,"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":["navigation","react","rescript","rescript-react","router","routing"],"created_at":"2024-12-18T23:15:28.997Z","updated_at":"2024-12-18T23:15:29.710Z","avatar_url":"https://github.com/DCKT.png","language":"ReScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ReScript Router\n\nThis is project is based on the great old [reroute](https://github.com/callstackincubator/reroute) module.\nIt's just using the latest Reason React API (hooks \u0026 context).\n\n[Checkout this simple demo](https://nifty-leakey-46cc44.netlify.com)\n\n## Setup\n\nInstall the module :\n\n```bash\n$ yarn add @dck/rescript-router\n```\n\nThen add it to your `bsconfig.json`:\n\n```json\n{\n  \"bs-dependencies\": [\"@rescript/react\", \"@dck/rescript-router\"]\n}\n```\n\n## Usage\n\n### Create your configuration\n\n```rescript\nopen RescriptRouter\n\nmodule RouterConfig = {\n  type t =\n    | Home\n    | About\n    | Hello(string)\n    | NotFound\n\n  let make = (url: RescriptReactRouter.url) =\u003e\n    switch url.path {\n    | list{} =\u003e Home\n    | list{\"about\"} =\u003e About\n    | list{\"hello\", name} =\u003e Hello(name)\n    | list{\"404\"}\n    | _ =\u003e\n      NotFound\n    }\n\n  let toString = (route: t) =\u003e\n    switch route {\n    | Home =\u003e \"/\"\n    | About =\u003e \"/about\"\n    | Hello(name) =\u003e \"/hello/\" ++ name\n    | NotFound =\u003e \"/404\"\n    }\n}\n\nmodule Router = CreateRouter(RouterConfig)\n```\n\n### Add the Provider\n\n```rescript\nmodule App = {\n  @react.component\n  let make = () =\u003e\n    \u003cRouter.Provider\u003e\n      {(~currentRoute) =\u003e \u003c\u003e\n        \u003cdiv className=\"container mx-auto p-4\"\u003e\n          \u003ch1 className=\"text-xl font-semibold text-center mb-4 text-blue-700\"\u003e\n            {\"RescriptRouter example\"-\u003eReact.string}\n          \u003c/h1\u003e\n          \u003cdiv className=\"flex flex-row items-center mb-4\"\u003e\n            \u003cCustomLink route=RouterConfig.Home\u003e {\"Home\"-\u003eReact.string} \u003c/CustomLink\u003e\n            \u003cCustomLink route=RouterConfig.About\u003e {\"About\"-\u003eReact.string} \u003c/CustomLink\u003e\n            \u003cCustomLink route={RouterConfig.Hello(\"dck\")}\u003e\n              {\"Route with params\"-\u003eReact.string}\n            \u003c/CustomLink\u003e\n          \u003c/div\u003e\n          {switch currentRoute {\n          | RouterConfig.Home =\u003e \u003ch1\u003e {\"Home\"-\u003eReact.string} \u003c/h1\u003e\n          | RouterConfig.About =\u003e \u003ch1\u003e {\"About\"-\u003eReact.string} \u003c/h1\u003e\n          | RouterConfig.Hello(name) =\u003e\n            \u003cdiv\u003e\n              \u003ch1\u003e {\"Route with params\"-\u003eReact.string} \u003c/h1\u003e\n              \u003cp\u003e {(\"Hi : \" ++ name)-\u003eReact.string} \u003c/p\u003e\n            \u003c/div\u003e\n          | _ =\u003e \u003ch1\u003e {\"404 not found\"-\u003eReact.string} \u003c/h1\u003e\n          }}\n        \u003c/div\u003e\n      \u003c/\u003e}\n    \u003c/Router.Provider\u003e\n}\n```\n\n### Use built-in Link module\n\nDon't forget to use it inside the Provider 😉\n\n```rescript\nmodule CustomLink = {\n  @react.component\n  let make = (~route: RouterConfig.t, ~children) =\u003e {\n    \u003cRouter.Link\n      className=\"rounded block px-3 py-2 bg-gray-200 mr-2 hover:bg-gray-300\"\n      activeClassName=\"bg-blue-500 text-white hover:bg-blue-600\"\n      route\u003e\n      children\n    \u003c/Router.Link\u003e\n  }\n}\n```\n\n### Full example\n\n```rescript\nopen RescriptRouter\n\nmodule RouterConfig = {\n  type t =\n    | Home\n    | About\n    | Hello(string)\n    | NotFound\n\n  let make = (url: RescriptReactRouter.url) =\u003e\n    switch url.path {\n    | list{} =\u003e Home\n    | list{\"about\"} =\u003e About\n    | list{\"hello\", name} =\u003e Hello(name)\n    | list{\"404\"}\n    | _ =\u003e\n      NotFound\n    }\n\n  let toString = (route: t) =\u003e\n    switch route {\n    | Home =\u003e \"/\"\n    | About =\u003e \"/about\"\n    | Hello(name) =\u003e \"/hello/\" ++ name\n    | NotFound =\u003e \"/404\"\n    }\n}\n\nmodule Router = CreateRouter(RouterConfig)\n\nmodule CustomLink = {\n  @react.component\n  let make = (~route: RouterConfig.t, ~children) =\u003e {\n    \u003cRouter.Link\n      className=\"rounded block px-3 py-2 bg-gray-200 mr-2 hover:bg-gray-300\"\n      activeClassName=\"bg-blue-500 text-white hover:bg-blue-600\"\n      route\u003e\n      children\n    \u003c/Router.Link\u003e\n  }\n}\n\nmodule App = {\n  @react.component\n  let make = () =\u003e\n    \u003cRouter.Provider\u003e\n      {(~currentRoute) =\u003e \u003c\u003e\n        \u003cdiv className=\"container mx-auto p-4\"\u003e\n          \u003ch1 className=\"text-xl font-semibold text-center mb-4 text-blue-700\"\u003e\n            {\"RescriptRouter example\"-\u003eReact.string}\n          \u003c/h1\u003e\n          \u003cdiv className=\"flex flex-row items-center mb-4\"\u003e\n            \u003cCustomLink route=RouterConfig.Home\u003e {\"Home\"-\u003eReact.string} \u003c/CustomLink\u003e\n            \u003cCustomLink route=RouterConfig.About\u003e {\"About\"-\u003eReact.string} \u003c/CustomLink\u003e\n            \u003cCustomLink route={RouterConfig.Hello(\"dck\")}\u003e\n              {\"Route with params\"-\u003eReact.string}\n            \u003c/CustomLink\u003e\n          \u003c/div\u003e\n          {switch currentRoute {\n          | RouterConfig.Home =\u003e \u003ch1\u003e {\"Home\"-\u003eReact.string} \u003c/h1\u003e\n          | RouterConfig.About =\u003e \u003ch1\u003e {\"About\"-\u003eReact.string} \u003c/h1\u003e\n          | RouterConfig.Hello(name) =\u003e\n            \u003cdiv\u003e\n              \u003ch1\u003e {\"Route with params\"-\u003eReact.string} \u003c/h1\u003e\n              \u003cp\u003e {(\"Hi : \" ++ name)-\u003eReact.string} \u003c/p\u003e\n            \u003c/div\u003e\n          | _ =\u003e \u003ch1\u003e {\"404 not found\"-\u003eReact.string} \u003c/h1\u003e\n          }}\n        \u003c/div\u003e\n      \u003c/\u003e}\n    \u003c/Router.Provider\u003e\n}\n\n```\n\n## Run demo\n\nInstall dependencies\n\n```\nyarn\n```\n\nCompiles ReScript files\n\n```\nyarn start\n```\n\nRun webpack-dev-server\n\n```\nyarn demo\n```\n\nGo to `http://localhost:8000`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdckt%2Frescript-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdckt%2Frescript-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdckt%2Frescript-router/lists"}