Skip to content

Instantly share code, notes, and snippets.

@dangdennis
Last active December 1, 2018 03:54
Show Gist options
  • Save dangdennis/1be8f271ca2cf9e09276f5d0d068c08f to your computer and use it in GitHub Desktop.
Save dangdennis/1be8f271ca2cf9e09276f5d0d068c08f to your computer and use it in GitHub Desktop.
initialState: () => {route: Home},
/* Inside the make function of a React component */
didMount: self => {
let watchId =
/* Re.React gives us Router API */
ReasonReact.Router.watchUrl(url =>
self.send(
/* url.search, url.hash is also available */
switch (url.path) {
| [""]
| []
/* We render whole pages based on our route constructors! */
| ["/"] => Home
| ["page1"] => Page1
| ["page2"] => Page2
| ["page3"] => Page3
| ["nested", "page4"] => Page4
| ["auth", wildCard] => WildCardPage(wildCard)
| _ => NotFound
},
)
);
self.onUnmount(() => ReasonReact.Router.unwatchUrl(watchId));
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment