bs-universal-router
Bucklescript bindings for Universal Router
Use
bs-universal-router
can be used with modern state management solutions like Meiosis to great effect. No need for Virtual DOMs or other "complex machinery" at this point in time ;)
See this video example
Writing bindings
To help write bucklescript bindings for this lib (and hence make it usable from ReasonML) see the FFI cheatsheet and go for it!
Install
npm i bs-universal-router
Add bs-universal-router
to dependencies
in bsconfig.json
Api
Api changes
TODO
Usage
open UniversalRouter;
let routes = {
path: "/page", /* string or regexp or array of them, optional */
name: "page", /* unique string, optional */
parent: None, /* Some(route) object or None */
children: Some([]), /* Some list of child route objects or None */
/* what to do when route activated */
action: (context, params) => {
/* some action */
}
};
let options = {
context: { },
baseUrl: "/base",
resolveRoute: (context, params) => {
if (typeof context.route.action === "function") {
context.route.action(context, params);
} else {
unit
};
},
errorHandler: (error, context) => {
Js.log(error);
Js.log(context);
if error.status === 404 {
"<h1>Page Not Found</h1>";
} else {
"<h1>Oops! Something went wrong</h1>";
};
}
};
let router = UniversalRouter.make(routes, ~options=options);
Build
npm run build
Watch
npm run watch
Editor
If you use vscode
, Press Windows + Shift + B
it will build automatically