import React from 'react' ; import { Route , Redirect } from 'react-router-dom' ; import { useSelector } from 'react-redux' ; import { StoreState } from 'store' ; interface AuthRouteProps { component : Function ; [ x ] : any ; } const AuthRoute = ( { component : Component , ... rest } ) => { const isAuthenticated = useSelector ( ( state ) => state . auth . isAuthenticated ) ; const checkingAuthStatus = useSelector ( ( state ) => state . loading [ 'auth/CHECK_AUTH' ] ) ; return ( < Route { ... rest } render = { props => checkingAuthStatus ? ( < > < />) : isAuthenticated ? (<Component {...props}/ > ) : ( < Redirect to = { { pathname : '/' , state : { from : props . location } } } />)}/ > ) ; } ; export default AuthRoute ;