asb_cloud_front/src/components/PrivateRoute.jsx
2021-04-09 17:59:35 +05:00

17 lines
409 B
JavaScript

import React /*, { useContext, createContext, useState }*/ from "react";
import {
Route,
Redirect
} from "react-router-dom";
export function PrivateRoute({ children, ...rest }) {
let token = localStorage['token'];
return (
<Route
{...rest}
render={({ location }) => token
? (children)
: (<Redirect to={{ pathname: "/login", state: { from: location } }} />)} />
);
}