reactjs - 清理本地存储后如何进行重定向?
问题描述
清理本地存储后,如何重定向到所需的页面?现在出现一个问题,用户按下按钮——退出,localalstorage被清空,但是重定向没有发生。
const onHandleSignOut = () => {
localStorage.removeItem('session');
return <Redirect to="/auth" />
}
<li className="header__mainmenu-item" onClick={() => onHandleSignOut()}>
<FaSignOutAlt />
</li>
解决方案
this.props.history.push("/auth");
希望对你有帮助...
推荐阅读
- c++ - 如何创建一个将学生姓名与其分数相匹配的数组?
- python - 如何将 'features="html.parser"' 添加到 BeautifulSoup 构造函数
- reactjs - 将使用 create react app 创建的 react 应用程序移动到另一台计算机
- php - 如何在html表格中显示选择框?
- java - 缓存其他实体映射的关系
- node.js - 使用 SQS 私有端点批量发送消息
- flask - 烧瓶中的 sqlalchemy.exc.OperationalError
- algorithm - 在一个数组中找到一个在线性时间内是其他任何一个数字的两倍大的数字
- sqlite - sqlite3.OperationalError:没有这样的表:page2
- docker - 在 Kubernetes 中调度和扩展 Pod