Reputation: 333
I'm trying to logout using this method: In render I have a div like this:
<div>
<a href="#" onClick={this.logout()}>LOGOUT</a>
</div>
and the logout function:
logout() {
// localStorage.clear();
location.href = 'localhost:3000';
}
At localhost:3000 I have the login page.
Put when I press logout, nothing happends. What can I do? Thank you
Upvotes: 12
Views: 46198
Reputation: 341
this solved my problem
logout() {
localStorage.clear();
window.location.href = '/';
}
Upvotes: 23
Reputation: 1995
Give to us the Minimal Example to be tested.
You already checked if your function is being called? Try to put some console.log
inside logout()
, it smells Binding to methods of React class issue.
Try to insert http:// inside location.href, like this: location.href = 'http://localhost:3000';
Upvotes: 3