26 lines
670 B
JavaScript

import React from 'react';
import { Route, Redirect } from 'react-router-dom';
import { connect } from 'react-redux';
export default function PrivateRoute(props) {
const { path, utente, component: Component } = props;
return (
<Route path={path} render={(properties) => (
utente
? <Component {...properties} />
: <Redirect to={{
pathname: '/login',
state: { from: properties.location }
}} />
)} />
);
}
const mapStateToProps = (state) => ({
utente: state.account.utente
});
PrivateRoute = connect(mapStateToProps)(PrivateRoute);