From 84cbb4872b61d89905d09ddfcfb3872b068438cc Mon Sep 17 00:00:00 2001 From: Jonathan Lovera Date: Tue, 27 Feb 2018 21:20:03 +1100 Subject: [PATCH] Create AllowRoutes.js AllowRoutes depending of an if statement and redirect if it's false. --- src/AllowRoutes.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/AllowRoutes.js 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; +}