Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Vue.js出现问题,当用户进行身份验证时,会很快显示登录屏幕(整页刷新)_Javascript_Vue.js - Fatal编程技术网

Javascript Vue.js出现问题,当用户进行身份验证时,会很快显示登录屏幕(整页刷新)

Javascript Vue.js出现问题,当用户进行身份验证时,会很快显示登录屏幕(整页刷新),javascript,vue.js,Javascript,Vue.js,我的路由工作正常,使用导航保护,用户登录后无法访问登录或注册路由。。但是,当我在addres bar/auth/signin中键入时,在重定向到仪表板之前不久会出现登录屏幕(因为它在每次之前的中检测到路由是requiresGuest) 有没有办法防止组件出现这样的闪光!? 这不是在创建组件之前触发的吗?更改if-else条件语句 router.beforeEach(function(to, from, next) { // prevent access to login & regi

我的路由工作正常,使用导航保护,用户登录后无法访问登录或注册路由。。但是,当我在addres bar
/auth/signin
中键入时,在重定向到仪表板之前不久会出现登录屏幕(因为它在每次之前的
中检测到路由是requiresGuest)

有没有办法防止组件出现这样的闪光!?
这不是在创建组件之前触发的吗?

更改if-else条件语句

router.beforeEach(function(to, from, next) {
  // prevent access to login & register after signing in
  if (to.matched.some(record => record.meta.requiresGuest) && auth.user.authenticated) {
    next({
      path: '/dashboard'
    });
  } else if (to.matched.some(record => record.meta.requiresAuth)) {
    if (!auth.user.authenticated) {
      next({
        path: '/auth/signin',
        query: {
          redirect: to.fullPath
        }
      })
    }
  } else {
    next() // make sure to always call next()!
  }
})
router.beforeEach(function(to, from, next) {
  // prevent access to login & register after signing in
  if (to.matched.some(record => record.meta.requiresGuest) && auth.user.authenticated) {
    next({
      path: '/dashboard'
    });
  } else if (to.matched.some(record => record.meta.requiresAuth)) {
    if (!auth.user.authenticated) {
      next({
        path: '/auth/signin',
        query: {
          redirect: to.fullPath
        }
      })
    }
  } else {
    next() // make sure to always call next()!
  }
})