asb_cloud_front/src/components/PrivateRoute.jsx

17 lines
409 B
React
Raw Normal View History

2021-04-09 17:59:35 +05:00
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 } }} />)} />
);
}