1
0
mirror of https://github.com/franjsco/tick3t synced 2025-01-14 02:16:15 +01:00

improvement: edit PrivateRoutes

This commit is contained in:
Francesco Esposito 2019-07-31 16:01:12 +02:00
parent 638a651795
commit 530f22c77e

View File

@ -1,15 +1,15 @@
import React from "react";
import { Redirect, Route } from "react-router-dom";
import { isLogin } from "./utils/auth";
export const PrivateRoute = ({ component: Component, ...rest }) => {
return (
<Route
{...rest}
render={props =>
isLogin() ? <Component {...props} /> : <Redirect to="/login" />
}
render={props => (
localStorage.getItem('user')
? <Component {...props} />
: <Redirect to={{ pathname: '/login', state: { from: props.location }}} />
)}
/>
);
};