Skip to main content

Posts

Showing posts with the label react router logout redirect

React logout redirect to login | logout component react Example

In the below examples, I Implementing client-side logout with React Router and there are two things I had to do to make this work: 1.       Clear the token in localStorage 2.       Push the url for the homepage onto the history prop Example 1, import   React , {  Component  }  from   'react' import  {  baseUrl  }  from   '../assets/js/helpers' ; export   default   class   Logout   extends   Component  {    logout  = ()  =>  {      window . localStorage . clear ();      window . location . href  =  baseUrl  +  "login" ;   }       render () {      return  (        < button   onClick = {this . logout } > Logout </ button > ...