后退按钮未在vuejs上检测到created()

问题描述 投票:0回答:1

所以我创建了一些代码

created() {
    if(!this.$session.exists() && !this.exists) {
      if(this.$router.currentRoute.path != '/login'){
        this.loginAlert = true
        this.$router.push('/login') 
      }
    }else{
      this.login = this.$session.get('uname')
      this.exists = true
    }
  },

当我刷新我的页面时,这是有效的

我的vue是localhost:8081

因此,当我打开localhost:8081时,它将警告尚未登录并重定向到localhost:8081 / login。但是重定向后,我在浏览器上按了向后按钮,则localhost:8081链接已打开,并且警报未显示,因此就像绕过]

我该如何解决?

所以我在创建的created()中有一些代码{if(!this。$ session.exists()&&!this.exists){if(this。$ router.currentRoute.path!='/ login'){this .loginAlert = true this。$ ...

vue.js back
1个回答
0
投票

您的组件仅创建一次,因此重定向后不会再次调用。您可以尝试在:key]上添加<router-view>

<router-view :key="$route.fullPath">

© www.soinside.com 2019 - 2024. All rights reserved.