mirror of
https://github.com/franjsco/tick3t
synced 2025-01-14 10:26:17 +01:00
improvement: edit PrivateRoutes
This commit is contained in:
parent
638a651795
commit
530f22c77e
@ -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 }}} />
|
||||
)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user