{"_id":"@drewschrauf/rerouter","_rev":"1-df93780bc10574cb582799b358dba8a7","name":"@drewschrauf/rerouter","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@drewschrauf/rerouter","version":"0.0.1","license":"MIT","scripts":{"build":"bsb -make-world","pretest":"yarn build","test":"jest"},"keywords":["reason","bucklescript","jest","react","router"],"dependencies":{"history":"^4.10.1"},"devDependencies":{"@drewschrauf/bs-jest-dom":"^0.1.4","@drewschrauf/bs-react-hooks-testing-library":"^0.1.1","@drewschrauf/bs-react-testing-library":"^0.1.5","@glennsl/bs-jest":"^0.5.1","bs-platform":"^7.3.2","react":"^16.13.1","react-dom":"^16.13.1","react-test-renderer":"^16.13.1","reason-react":"^0.8.0"},"peerDependencies":{"reason-react":">= 0.7.0"},"publishConfig":{"access":"public"},"description":"Rerouter is a minimal router for [ReasonReact](https://reasonml.github.io/reason-react/) projects. It uses [history](https://github.com/ReactTraining/history) under the hood to make testing simple.","licenseText":"MIT License\n\nCopyright (c) 2020 Drew Schrauf\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject 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,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@drewschrauf/rerouter@0.0.1","dist":{"shasum":"7719cec2f2ec52e4d213a79d66d6f7e38634ec54","integrity":"sha512-fqBXJ7TVpL5ocnuC/s9O9h1MKEwUabgJYwoa60LPe7Dik0wSTYtNSX8xxnPkm2zaoGOGCZLdcDF/cgvixG16FA==","tarball":"https://registry.npmjs.org/@drewschrauf/rerouter/-/rerouter-0.0.1.tgz","fileCount":11,"unpackedSize":10289,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeySqxCRA9TVsSAnZWagAAeFUP/RwT2gsIkTipZe97Zo/d\nvM41cJbGspkPVUctbb5N5o1TIRgJGIY44NOVCZCLgXTZ+vUpgds+y6l+rnCd\nQgWJcrbSgYO9DfbIjnt4jFy5CkciWdZnmh/kyILByTFBBntww87eu1558pOZ\nBFVNkNPbwRE82srpAgwL099BbRjCb/5pAARmFyWYF2R6rXhLJXKPgMceWYIm\nmUvg32CICtbXE7vzMIMyHiaQznK8l6bf064oXH7bWolx8xVD/lYLHh9ieaqZ\nCgQZcJb9cY4Hmsabjmez87S69T0Euw0S7GJJ2dXbS53PPhjpRJYyD8WlrDDI\n2qb5lNgtzYN4grkcV9mEcgSeVpavyhSGZy3F74fb10rAFapnbuKhHdpBc3ht\n6lUF3SbM/QTlOPNT4WKoy+ZAL3GXj+Bz4Jw8RXkL8DKuZDWPhoBtCduz3uC/\nv8DW/J6yiJ7eqkahNvUVT26Qtn8zxCHPPaXOD/PC7ZzOPOTmqNN4Wdix/MGE\nToS9/XXvHVpSYOzru/MtGV4/Xthb4pxoGGJ5CrkRtreHJAGLt8heqR0z0dIU\n6YZcQo18/jrG38tjzdnVo3VLrRPzj1sy+fssp6Z3vPd4lYCzo0fnrPvbo/Su\ntPf9gIdiNnYAq4WIga7Lf5ZqdvUw3uzXCTVdOe2WfvYXSQG0lY2FyNh9xzIb\nh3rL\r\n=H0zL\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAUSmEEow5GILxsnMbCeCMmMbi0D+QGhhHyK6Vh/iltfAiBPIE08xF05NZdjwLihYHWyugfYYinnJ+rjxhv5KpviWA=="}]},"maintainers":[{"name":"drewschrauf","email":"andrew.schrauf@gmail.com"}],"_npmUser":{"name":"drewschrauf","email":"andrew.schrauf@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rerouter_0.0.1_1590241968781_0.5560058806892996"},"_hasShrinkwrap":false}},"time":{"created":"2020-05-23T13:52:48.735Z","0.0.1":"2020-05-23T13:52:48.902Z","modified":"2022-04-05T05:38:46.131Z"},"maintainers":[{"name":"drewschrauf","email":"andrew.schrauf@gmail.com"}],"description":"Rerouter is a minimal router for [ReasonReact](https://reasonml.github.io/reason-react/) projects. It uses [history](https://github.com/ReactTraining/history) under the hood to make testing simple.","keywords":["reason","bucklescript","jest","react","router"],"license":"MIT","readme":"# Rerouter\n\nRerouter is a minimal router for [ReasonReact](https://reasonml.github.io/reason-react/) projects. It uses [history](https://github.com/ReactTraining/history) under the hood to make testing simple.\n\n## Wait, doesn't ReasonReact have a built-in router?\n\n[Yes](https://reasonml.github.io/reason-react/docs/en/router.html)! An excellent one, in fact.\n\nHowever, its strength is also its weakness. It provides very thin bindings to the browser's API for reading and updating the URL. Unfortunately, these APIs are not supported by [Jest](https://jestjs.io/) (and, by extension, [@glennsl/bs-jest](https://github.com/glennsl/bs-jest)).\n\nThis router makes use of history to enable the use of the browser history in the browser and an in-memory history for testing.\n\n## Installation\n\nJust install the package\n\n```bash\nyarn add @drewschrauf/rerouter\n```\n\nand add it to your `bsconfig.json`\n\n```json\n{\n    ...,\n    \"bs-dependencies\": {\n    \t...,\n    \t\"@drewschrauf/rerouter\"\n\t}\n}\n```\n\n## Usage\n\nSimply wrap the `<Rerouter />` component around your application and you're good to go.\n\n```reason\n/* Index.re */\nReactDOMRe.renderToElementWithId(<Rerouter> <App /> </Rerouter>)\n```\n\nWithin your app you can make use of `useUrl()` and `useHistory()` to get your current location and update it respectively.\n\nWhen you're writing your tests (ideally with [@glennsl/bs-jest](https://github.com/glennsl/bs-jest) and [@drewschrauf/react-testing-library](https://github.com/drewschrauf/bs-testing-library)), render your app inside a `<Rerouter />` component with a memory history instead.\n\n```reason\n/* MyTest_test.re */\ntest(\"app should render\", () => {\n\tlet history = Rerouter.History.createMemoryHistory(~initialEntries=[\"/\"], ());\n\trender(<Rerouter history> <App /> </Rerouter>);\n})\n```\n\n## API\n\nThe API is heavily based on [ReasonReactRouter](https://reasonml.github.io/reason-react/docs/en/router). It's worth giving their own documentation a read to see why this approach to a React router is so perfect for Reason.\n\n### Context and Hooks\n\n**`<Rerouter history=option(Rerouter.History.t) />`**\n\nThe history context provider. The must be wrapped around your application in order to be able to use the following hooks. If no `history` is passed, a browser history is instantiated and used.\n\n**`useUrl(): { path: list(string), search: string, hash: string }`**\n\nRetrieves the current URL parts. The API is identical to that provided by ReasonReactRouter.\n\n**`useHistory(): Rerouter.History.t`**\n\nRetrieves the history object. This is required for passing to the `push` and `replace` methods below.\n\n### History\n\n**`createBrowserHistory(~basename: string=?, ~forceRefresh: bool=?, ~keyLength: int=?, ()): Rerouter.History.t`**\n\nCreate a history object for use within the browser. You usually won't need to call this yourself unless you want to customise the instance. Using `<Rerouter />` without a `history` argument will instantiate one of these by default.\n\n**`createMemoryHistory(~initialEntries: list(string)=?, ~initialIndex: int=?, ~keyLength: int=?, ()): Rerouter.History.t`**\n\nCreate a history object for use in tests. Pass this as the `history` prop of your `<Rerouter />` context provider.\n\n**`push(history: Rerouter.History.t, url: string): unit`**\n\nNavigate to the given URL.\n\n**`replace(history: Rerouter.History.t, url: string): unit`**\n\nNavigate to the given URL, replacing the current URL in the history.","readmeFilename":"README.md"}