ReasonReact comes with a built-in router found in the ReasonReact.Router module. It is quite unopinionated and therefore flexible. The public API has only four functions:
- ReasonReact.Router.watchUrl: (url => unit) => watcherID
- ReasonReact.Router.unwatchUrl: watcherID => unit
- ReasonReact.Router.push: string => unit
- ReasonReact.Router.dangerouslyGetInitialUrl: unit => url
The watchUrl function starts watching the URL for changes. When changed, the url => unit callback is called. The unwatchUrl function stops watching the URL.
The push function sets the URL, and the dangerouslyGetInitialUrl function gets a record of type url. The dangerouslyGetInitialUrl function is meant to be used only within the didMount lifecycle hook, alongside watchUrl, to prevent issues with stale information.
The url type is defined as follows:
type url = {
path: list...