After uniapp logs out, clear the user's browser forward and back buttons or gestures to jump to the page

export default {
  methods: {
    logout() {
      // 清除本地存储的用户登录信息等
      // ...

      // 跳转到登录页,并清除浏览器的历史记录
      uni.reLaunch({
        url: '/pages/login/login',
        success() {
          history.pushState(null, null, location.href);
        }
      });
    }
  }
}

In the above code, the uni.reLaunch method is used to jump to the login page. In the success callback function of this method, the history.pushState method is used to add the URL of the current page to the browser's history, so that the browser's forward and The back button will not work.

It should be noted that this method may have a certain impact on user experience, so it needs to be used with caution. In addition, this method can only clear the history records before the current page, but cannot clear the history records of the current page and after.

Guess you like

Origin blog.csdn.net/weixin_46324536/article/details/129630351