Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.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,我有一个受保护的路由,用户登录后可以访问该路由。我想做的是,一旦他点击一个div,就将他重定向到主页,目前它不起作用,因为我得到以下两个错误: Error: Redirected when going from "/captables" to "/home" via a navigation guard. 我做错了什么导致了这些错误?我如何修复它们 这是我的index.js: import firebase from "firebase/app

我有一个受保护的路由,用户登录后可以访问该路由。我想做的是,一旦他点击一个div,就将他重定向到主页,目前它不起作用,因为我得到以下两个错误:

Error: Redirected when going from "/captables" to "/home" via a navigation guard.
我做错了什么导致了这些错误?我如何修复它们

这是我的index.js:

import firebase from "firebase/app";
import "firebase/auth";
                                                
import Multibaas from '../components/MultibaasExample.vue'
Vue.use(Router)

const router =  new Router({
  routes: [
    {
      path: '/',
      name: 'Login',
      component: Login
    },
    {
      path: '/home',
      name: 'Home',
      component: Home
    },
    {
      path: '/unauthorized',
      name: 'Unauthorized',
      component: Unauthorized
    },
    {
      path: '*',
      component: NotFound,
      name: 'NotFound',
    },
    {
      path: '/multibaas',
      name: 'Multibaas',
      component: Multibaas
    },
    {
      path: '/captables',
      name: 'CapTables',
      component: CapTables,
      meta: {
        requiresAuth: true
      },
    },
  ],
  mode: 'history'
})

router.beforeEach((to, from, next) => {
 const currentUser = firebase.auth().currentUser
 const requiresAuth = to.matched.some(record => record.meta.requiresAuth)

 if(requiresAuth && !currentUser) next('/')
   else if (!requiresAuth && currentUser) next('home')
   else next()
});

export default router
我试图更改“下一步到
路由器推送”
,但效果不大

这是我的html:

      <md-button class="view-captable-btn" v-for="item in capTables" :key="item.contractAddress" 
        @click="navigateAway"> 
        <p>{{item.label}}</p>
        <p class="contract-address-p"> {{item.contractAddress}}</p>
       </md-button>
下面是控制台日志堆栈:

Error: Redirected when going from "/captables" to "/home" via a navigation guard.
    at createRouterError (vue-router.esm.js?8c4f:2008)
    at createNavigationRedirectedError (vue-router.esm.js?8c4f:1967)
    at eval (vue-router.esm.js?8c4f:2314)
    at eval (index.js?a18c:58)
    at iterator (vue-router.esm.js?8c4f:2300)
    at step (vue-router.esm.js?8c4f:1947)
    at step (vue-router.esm.js?8c4f:1951)
    at runQueue (vue-router.esm.js?8c4f:1955)
    at HTML5History.confirmTransition (vue-router.esm.js?8c4f:2330)
    at HTML5History.transitionTo (vue-router.esm.js?8c4f:2203)

把你的
*
路线放在最后。看到了吗,我刚刚这么做了,但仍然收到相同的错误扫描您创建了一个stackbiltz示例我用console.log结果更新了我的问题在调用
next
->
时在
home
之前添加
/
,否则(!requireAuth&¤tUser)next('/home')
navigateAway() {
        this.$router.push('/home')
      }
Error: Redirected when going from "/captables" to "/home" via a navigation guard.
    at createRouterError (vue-router.esm.js?8c4f:2008)
    at createNavigationRedirectedError (vue-router.esm.js?8c4f:1967)
    at eval (vue-router.esm.js?8c4f:2314)
    at eval (index.js?a18c:58)
    at iterator (vue-router.esm.js?8c4f:2300)
    at step (vue-router.esm.js?8c4f:1947)
    at step (vue-router.esm.js?8c4f:1951)
    at runQueue (vue-router.esm.js?8c4f:1955)
    at HTML5History.confirmTransition (vue-router.esm.js?8c4f:2330)
    at HTML5History.transitionTo (vue-router.esm.js?8c4f:2203)