Home > Mobile >  How to navigate react page on ternary operators?
How to navigate react page on ternary operators?

Time:12-11

I'm trying to navigate to Authentication page (login page) if isLoggedIn is false using ternary operator but this isn't working. Can you help please?

export default function Admin(props) {

let navigate=useNavigate();
  return <>{props.isLoggedIn ?  <div>
     <Row className={stylesadmin.root}> 
     <Uploader/>
     <ToastContainer/>  
     </Row>
     </div> : navigate(`/Auth`) }</>
}

CodePudding user response:

You can use react-router Redirect component

return <>{props.isLoggedIn ?  (<div>
   <Row className={stylesadmin.root}> 
     <Uploader/>
     <ToastContainer/>  
   </Row>
 </div>) : <Redirect to='/Auth'/> }</>
}

CodePudding user response:

you can use either Redirect component or use useHistory hook from react-router-dom

  • Related