首页 > 解决方案 > React JS中用户注销时如何缓存清除

问题描述

import React, { Component } from "react";

export default class logout extends React.Component {

    executeBasicAuthenticationService() {

    }

    logout(event) {
        this.executeBasicAuthenticationService()
            .then(() => {
                sessionStorage.removeItem(USER_NAME_SESSION_ATTRIBUTE_NAME); 
                sessionStorage.clear();
                window.location.href="/";
            })
            .catch(() => {})

    }

标签: reactjs

解决方案


您可以将其放在 head 标记中以清除浏览器缓存:

<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>

如本文所述:

https://thewebdev.info/2021/10/03/how-to-clear-browser-cache-in-react/#:~:text=To%20clear%20browser%20cache%20in%20React%2C%20we% 20can%20add%20meta,%20page%20 没有 %20cached。&text=in%20the%20head%20tag%20to,make%20sure%20nothing%20is%20cached


推荐阅读