Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
On logging out , the siderbar component is still visible

Blockquote : this is the sidebar component, where the logout button and its method are written. for reference, I have shared the image below

function sidelink(val)
{
  
  return(
<li className={val.lis}>
       <i className={val.icon} aria-hidden="true"></i>
       <Link to={val.link} className={val.slink}>{val.name}</Link>
   </li>
  );
} 
function SideBar() {

  const history = useHistory();
  function logout() {
    localStorage.clear();
    history.push("/");
  }
  
    return (
     ...
       <Link onClick={logout} className="text-white text-decoration-none">LOGOUT</Link>
   ...
    )
}

export default SideBar

enter image description here

    function Admin() {  
const history = useHistory();
useEffect(()=> {
 if (!(localStorage.getItem('user_login'))&&!(localStorage.getItem('admin_login')))
  {
   
 history.push("/")
  }
    else
    {
        history.push("/admin")
    }
  },[])
  return (
      <div>
      <Router>
          <SideBar/>
              <Switch>
                  <Route exact path="/admin" component={Main}></Route>
                  <Route exact path="/course" component={CourseSection}></Route>
                  <Route exact path="/subject" component={SubjectSection}></Route>
                  <Route exact path="/faculty" component={FacultySection}></Route>
                  <Route exact path="/class" component={ClassSection}></Route>
                  <Route exact path="/constrain" component={ConstrainSection}></Route>
                  <Route exact path="/timetable" component={TimetableSection}></Route>
              </Switch>
      </Router>
      </div>
  )
}
export default Admin

Blockquote

on logging out the URL and main component working correctly but the sidebar component is still visible and after reloading it logout correctly

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To achieve that you can use useState() hook to determine the state of authenticity.

    function Admin() {  
const history = useHistory();
//useState() ------
const [login,setLogin] = useState(false);
useEffect(()=> {
 if (!(localStorage.getItem('user_login'))&&!(localStorage.getItem('admin_login')))
  {
   //Not authenticated -------
   setLogin(false)
 history.push("/")
  }
    else
    {
   //Authenticated -------

      setLogin(true)
        history.push("/admin")
    }
  },[])
  return (
      <div>
      <Router>
          {login?<SideBar/>:""}
              <Switch>
                  <Route exact path="/admin" component={Main}></Route>
                  <Route exact path="/course" component={CourseSection}></Route>
                  <Route exact path="/subject" component={SubjectSection}></Route>
                  <Route exact path="/faculty" component={FacultySection}></Route>
                  <Route exact path="/class" component={ClassSection}></Route>
                  <Route exact path="/constrain" component={ConstrainSection}></Route>
                  <Route exact path="/timetable" component={TimetableSection}></Route>
              </Switch>
      </Router>
      </div>
  )
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!