reactjs - TypeError:注销期间未定义历史记录
问题描述
我已经实现了一个简单的注销功能,它可以清除所有 cookie 并删除本地存储。登录时,它可以完美运行,并且还会创建相应的令牌和本地存储。我在下面附上了图片这里 为客户端登录创建了 token1。并为员工登录创建了令牌
一旦我注销,它就会清除令牌。但是,它会抛出以下错误,说明历史未定义。我也在我的登录页面中创建了一个变量历史记录。我无法弄清楚错误。我在下面附上了代码:;
带有注销按钮的顶部导航栏:
export const ClientTopNavigationBar = ({ history }) => {
const handleClientLogout = (evt) => {
clientLogout(() => {
history.push("/ClientLogin");
});
};
const ShowClientTopNavigationBar = () => (
<Styles>
<Navbar expand="lg">
<img src="/images/logo1.png" height="50" alt="Logo" />
{isClientAuthenticated() && (
<Fragment>
<button
className="btn btn-link text-decoration-none logout-btn"
onClick={handleClientLogout}
>
logout
</button>
</Fragment>
)}
</Navbar>
</Styles>
);
//render
return <header id="header">{ShowClientTopNavigationBar()}</header>;
};
export default withRouter(ClientTopNavigationBar);
auth.js 中的客户端身份验证
export const setClientAuthentication = (token1, client) => {
setCookie("token1", token1);
setLocalStorage("client", client);
};
export const isClientAuthenticated = () => {
if (getCookie("token1") && getLocalStorage("client")) {
return getLocalStorage("client");
} else {
return false;
}
};
export const clientLogout = (next) => {
deleteCookie("token1");
deleteLocalStorage("client");
next();
};
解决方案
推荐阅读
- mysql - 远程服务器上的mysqldump到本地机器:错误:1045:用户'root'@'10.213.213.11'的访问被拒绝
- sql-server - 在具有多个 CTE 的外部查询中将结果标记为文本标签
- powershell - 使用 powershell 从 SharePoint 列表中简单搜索和替换项目
- reactjs - 如何动态更新 MapboxGL.ShapeSource?
- scala - 无法从 Spark 连接到 S3 - AmazonS3Exception 状态代码:400
- google-cloud-platform - Cloud Run 部署到 GKE 无法更改 URL
- azure - Azure 服务总线主题作为 Google PubSub 推送订阅者
- java - 将 Exoplayer 演示与 Firebase 实时数据库一起使用
- swift - 可扩展的表格单元格内容从单元格溢出
- python - 有没有办法修复 python 3 中的最大递归级别?