1
0
mirror of https://github.com/franjsco/tick3t synced 2025-01-14 10:26:17 +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 React from "react";
import { Redirect, Route } from "react-router-dom"; import { Redirect, Route } from "react-router-dom";
import { isLogin } from "./utils/auth";
export const PrivateRoute = ({ component: Component, ...rest }) => { export const PrivateRoute = ({ component: Component, ...rest }) => {
return ( return (
<Route <Route
{...rest} {...rest}
render={props => render={props => (
isLogin() ? <Component {...props} /> : <Redirect to="/login" /> localStorage.getItem('user')
} ? <Component {...props} />
: <Redirect to={{ pathname: '/login', state: { from: props.location }}} />
)}
/> />
); );
}; };