import React from 'react'
import { Redirect, Route } from 'react-router-dom'
const Protected = ({ component, ...rest }) => {
<Route
{...rest}
render={() => {
localStorage.getItem('login') ? (
<component {...props} />
) : (
<Redirect to='/login' />
)
}}
/>
};
export default Protected
// app.js
import Protected from'./components/Protected'
<Router>
<Protected exact path="/"component={Home}/>
<Protected exact path="/about"component={About}/>
<Protected exact path="/contact"component={Contact}/>
</Router>