{"id":13800254,"url":"https://github.com/coot/purescript-cofree-react-router","last_synced_at":"2025-07-28T07:32:05.847Z","repository":{"id":58239063,"uuid":"84249116","full_name":"coot/purescript-cofree-react-router","owner":"coot","description":"React-Router implemented in PureScript as Cofree Comonad for the Array functor.","archived":false,"fork":false,"pushed_at":"2018-03-11T21:27:20.000Z","size":358,"stargazers_count":25,"open_issues_count":3,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-16T01:40:00.548Z","etag":null,"topics":["cofree-comonad","purescript","react-router"],"latest_commit_sha":null,"homepage":null,"language":"PureScript","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/coot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-07T21:43:42.000Z","updated_at":"2024-10-31T22:09:44.000Z","dependencies_parsed_at":"2022-08-31T00:30:50.701Z","dependency_job_id":null,"html_url":"https://github.com/coot/purescript-cofree-react-router","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coot%2Fpurescript-cofree-react-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coot%2Fpurescript-cofree-react-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coot%2Fpurescript-cofree-react-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coot%2Fpurescript-cofree-react-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coot","download_url":"https://codeload.github.com/coot/purescript-cofree-react-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227877785,"owners_count":17833559,"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":["cofree-comonad","purescript","react-router"],"created_at":"2024-08-04T00:01:10.839Z","updated_at":"2024-12-03T08:13:24.072Z","avatar_url":"https://github.com/coot.png","language":"PureScript","readme":"# Cofree React Router\n\n[![Maintainer: coot](https://img.shields.io/badge/maintainer-coot-lightgrey.svg)](http://github.com/coot)\n[![Documentation](https://pursuit.purescript.org/packages/purescript-cofree-react-router/badge)](https://pursuit.purescript.org/packages/purescript-cofree-react-router)\n[![Build Status](https://travis-ci.org/coot/purescript-cofree-react-router.svg?branch=master)](https://travis-ci.org/coot/purescript-cofree-react-router)\n\n## Installation\n\n```\nbower i --save purescript-cofree-react-router\nnpm i --save warning react react-dom\n```\n\n## Intro\n\nRouting library for `React` in the spirit of\n[react-router](https://github.com/ReactTraining/react-router) v3.\nThe router has type\n```purescript\ntype Router props args = (RoutePropsClass props) =\u003e Cofree List (Tuple (Route props args) (Maybe (IndexRoute props args)))\n```\nthus it is a cofree comonad for the `Array` functor.\n\nYou can define router using `:+` (adds routes without index) and `:\u003c` (the\nstandard combinator for unfolding a cofree comonad) combinators:\n```purescript\nrouter :: Router RouteProps Unit\nrouter =\n  Route \"main\" (unit \u003c$ lit \"\") mainClass :+\n    (Route \"home\" (unit \u003c$ lit \"home\") homeClass :+ Nil)\n    : (Tuple (Route \"user\" (unit \u003c$ (lit \"user\" *\u003e int)) userClass) (Just $ IndexRoute \"user-index\" userIndexClass) :\u003c\n        (Route \"book\" (unit \u003c$ (lit \"books\" *\u003e int)) bookClass :+\n          (Route \"pages\" (unit \u003c$ lit \"pages\") pagesClass :+\n            (Route \"page\" (unit \u003c$ int) pageClass :+ Nil)\n            : Nil)\n          : Nil)\n        : Nil)\n    : (Route \"user-settings\" (unit \u003c$ (lit \"user\" *\u003e int *\u003e lit \"settings\")) settingsClass :+ Nil)\n    : Nil\n```\n\n## Applicative parser\nUrls are parsed using the applicative parser from\n[routing](https://pursuit.purescript.org/packages/purescript-routing) package.\nThere are some assumptions:\n* if you need to use query args, the router is taking care of them and the\n  parsed dictionary is made available in `RouteParams` for all the routes.  The\n  cofree router will go through the parsed url and sum all query maps and use\n  that.  You can still match `params` in parts of the url, but then they will\n  be available only for that route.\n* The router will match end of url with `end \u003c|\u003e lit \"\" *\u003e end \u003c|\u003e params *\u003e end`\n  to check if all the route parts where exhousted.  This matches end, trailing\n  \"/\" or trailing search params.\n\n## Browser history\nFor now, only browser history is supported, but it's not to difficult to change\nthe\n[browserRouter](https://github.com/coot/purescript-cofree-react-router/blob/master/src/React/Router/Components.purs#L52)\nspec to use hash history.\n\n## Server side rendering\nFor server side rendering use `matchRouter`.  Checkout the [isomorphic react\nexample](https://github.com/coot/purescript-isomorphic-react-example) how to\nset-up server side rendering together with [hyper](https://github.com/owickstrom/hyper).\n\n## Example\nCheckout the included example. To build and run type\n```bash\nnpm run example\n```\nNow open `http://localhost:8080` in your prefered browser.\n","funding_links":[],"categories":["URL Routers"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoot%2Fpurescript-cofree-react-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoot%2Fpurescript-cofree-react-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoot%2Fpurescript-cofree-react-router/lists"}