Created
January 15, 2018 19:06
-
-
Save kgoggin/b70d787d2e6ba5bfe8f636c597a15705 to your computer and use it in GitHub Desktop.
Reason Routing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let getRouteComponent: ReasonReact.Router.url => ReasonReact.reactElement = | |
(url) => | |
switch (MainRoutes.match(url)) { | |
| Home(_url) => <Page message="Home" /> | |
| Admin(route) => <AdminRoot route /> | |
| NotFound(_url) => <Page message="404" /> | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open ReasonReact.Router; | |
module type RouteType = {type t; let match: url => t;}; | |
module AdminRoutes: RouteType = { | |
type t = | |
| Root(url) | |
| Transactions(option(string), url) | |
| Members(option(string), url) | |
| NotFound(url); | |
let match = (url) => | |
switch url.path { | |
| [] => Root(url) | |
| ["transactions"] => Transactions(None, url) | |
| ["transactions", id] => Transactions(Some(id), url) | |
| ["members"] => Members(None, url) | |
| ["members", id] => Members(Some(id), url) | |
| _ => NotFound(url) | |
}; | |
}; | |
module MainRoutes: RouteType = { | |
type t = | |
| Home(url) | |
| Admin(AdminRoutes.t) | |
| NotFound(url); | |
let match = (url) => | |
switch url.path { | |
| [] => Home(url) | |
| ["admin", ...rest] => Admin(AdminRoutes.match({...url, path: rest})) | |
| _ => NotFound(url) | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment