February 2019
Beginner to intermediate
180 pages
4h 4m
English
Since url.path of ReasonReact.Router is a list of strings, and our Router.route.href is a string, we need a way to convert from string to a list of strings:
let hrefToPath = href => Js.String.replaceByRe([%bs.re "/(^\\/)|(\\/$)/"], "", href) |> Js.String.split("/") |> Belt.List.fromArray;
We also need a way to convert a url to a route for use in initial state, as well as within the callback function of watchUrl:
let urlToRoute = (url: ReasonReact.Router.url) => switch ( Belt.List.getBy(routes, route => url.path == hrefToPath(route.href)) ) { | None => Belt.List.headExn(routes) | Some(route) => ...Read now
Unlock full access