Last active
December 1, 2018 03:54
-
-
Save dangdennis/1be8f271ca2cf9e09276f5d0d068c08f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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