forked from ddrilling/asb_cloud_front
17 lines
409 B
React
17 lines
409 B
React
|
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 } }} />)} />
|
||
|
);
|
||
|
}
|