There is a problem with sessionStorage

  1. users log in and use sessionStorage to save token
  2. when the user logs out, use the clear method to clear, sessionStorage to empty, and router to the landing page
  3. there is a problem. When you click on the previous page of the browser, sessionStorage still exists.

could you tell me how to solve this problem?

Mar.06,2021

see if the code is re-assigned


in the above page, you need to find out whether there are methods such as reassigning, created mounted activated and so on.
but in fact, you have to write a beforeEach judgment in main. If you don't have the value of session, other pages can't go. I'll give you a reference from my project below

.
// token 
router.beforeEach((to, from, next) => {
    
    const TOKEN = window.localStorage.getItem('token');
    //NProgress.start(); 
    if(!TOKEN && !['/loginDemo', '/logindemo', '/login'].includes(to.path)){
        loginHref(next, { path: '/login' });
    } else {
        next();
    }
});
Menu