我正在尝试使用此方法注销: 在渲染中,我有一个像这样的div:
<div>
<a href="#" onClick={this.logout()}>LOGOUT</a>
</div>
和退出功能:
logout() {
// localStorage.clear();
location.href = 'localhost:3000';
}
在localhost:3000我有登录页面。
当我按下注销时,没有任何事情发生。我能做什么? 谢谢
答案 0 :(得分:3)
向我们提供要测试的最小示例。
您是否已检查过您的函数是否被调用?尝试在console.log
内放置一些logout()
,它会引发Binding to methods of React class问题。
尝试在location.href中插入http://,如下所示:location.href = 'http://localhost:3000';
答案 1 :(得分:2)
这解决了我的问题
logout() {
localStorage.clear();
window.location.href = '/';
}