import React from 'react' ; import { Switch , useLocation } from 'react-router-dom' ; import { useSession } from 'bonde-core-tools' ; interface SessionRedirectProps { paths : string [ ] ; to ? : string ; loading : any ; } const SessionRedirect = ( { children , loading : Loading , paths } ) => { const { isLogged } = useSession ( ) ; const location = useLocation ( ) ; const isRendered = ! ( isLogged && paths . filter ( ( path ) => location . pathname === path ) . length > 0 ) ; return isRendered ? ( < Switch > { children } < /Switch>) : <Loading fetching='redirect'/ > ; } ; SessionRedirect . defaultProps = { paths : [ ] } ; export default SessionRedirect ;