aboutsummaryrefslogtreecommitdiff
path: root/src/core/custom.router.js
diff options
context:
space:
mode:
authorIndrajith K L2019-12-11 18:54:05 +0530
committerIndrajith K L2019-12-11 18:54:05 +0530
commit8988233da897e8447a1dbdb700836fb8576e5e6b (patch)
tree0bcaaf9657f35320ea110085ed0c40f815100a55 /src/core/custom.router.js
parent53e5edb3d93d957f82034be43940d560540525a8 (diff)
downloadreact-redux-saga-starter-8988233da897e8447a1dbdb700836fb8576e5e6b.tar.gz
react-redux-saga-starter-8988233da897e8447a1dbdb700836fb8576e5e6b.tar.bz2
react-redux-saga-starter-8988233da897e8447a1dbdb700836fb8576e5e6b.zip
:tada: Initial Commit
Diffstat (limited to 'src/core/custom.router.js')
-rw-r--r--src/core/custom.router.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/core/custom.router.js b/src/core/custom.router.js
new file mode 100644
index 0000000..b3f08ec
--- /dev/null
+++ b/src/core/custom.router.js
@@ -0,0 +1,27 @@
+import React from "react";
+import { Route, Redirect } from "react-router-dom";
+import Storage from "../services/storage.service";
+
+export const CustomRouter = ({ xComponent: Component, ...xProps }) => {
+ return (
+ <Route
+ {...xProps}
+ render={props => {
+ console.log(props.permissions)
+ let token = Storage.get("token");
+ let pathName = props.match.path;
+ if (!token && pathName !== "/login") {
+ return <Redirect to="/login" />;
+ } else if (pathName === "/login" && token) {
+
+ return <Redirect to="/dashboard" />;
+ }else if (pathName === "/" && token) {
+
+ return <Redirect to="/dashboard" />;
+ }
+ debugger
+ return <Component {...props} />;
+ }}
+ />
+ );
+ }; \ No newline at end of file