diff --git a/src/AllowRoutes.js b/src/AllowRoutes.js new file mode 100644 index 0000000..d74d7c7 --- /dev/null +++ b/src/AllowRoutes.js @@ -0,0 +1,17 @@ +import {h} from 'hyperapp'; +import {Redirect} from "./"; + +export default({ + if: _if, + redirectTo = '/' +}, children) => { + const redirect = () => ; + + if (!_if && window.location.pathname !== redirectTo && children.length) + redirect(); + + if (_if) + return children; + + return null; +}