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