✔ Idiomatic Reason usage throughout
✔ Type checking for all function arguments/returns/options, and location descriptors.
✔ Take advantage of Variant types for action types (POP|PUSH|REPLACE) and blocker functions (Prompt message | Block| Pass);
- push
- replace
- createBrowserHistory
- listen/unlisten
- block/unblock (for push/replace)
- createHref
- block for POPs
- basename
- createHashHistory
/* Example usages */
/* state could be anything but you must define its type before calling createBrowserHistory */
type state = {mystate: string};
/* location.state is a variant of | Some state and | None */
let logState = fun
| Some {mystate: value} => Js.log "Current state value: " ^ value
| None => Js.log "No state";
let actionToString = fun
| Pop => "POP"
| Push => "PUSH"
| Replace => "REPLACE";
let history = History.createBrowserHistory ();
let unsub = History.subscribe history (fun action location => {
Js.log (actionToString action);
Js.log location.key;
logState location.state
});
History.push history "/route1#someid";
let unblock = History.block history (fun _action _location => {
/* Callback function can return either */
Prompt "Are you sure you want to leave this page??";
/* or */
Block
/* or */
Pass
});
/* This will show a prompt before transitioning */
History.push history "/route2" state::{mystate: "state1"};
/* Detach listeners */
unblock ();
unsub ();