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 > ...
Angular, React, JavaScript, Java, PHP, SQL, C#, Vue, NodeJs, TypeScript and Interview Questions Answers