带有 Navigation Guards 的 vue 路由器- next() 不工作

vue router with Navigation Guards- next() not working

使用 Navigation Guards 保护 Vue 路由。 Navigation Guards 在加载或刷新时工作,但是 next() 函数在使用 <router-link>.

访问路由时不起作用
<router-link to="{ name: 'page1' }" >Page 1</router-link>

导航守卫代码。

{
   path: '/page1',
   component: page1,
   name: 'page1',
   meta: { auth: true },
   beforeEnter: (to, from, next) => {
     if (!store.state.roles.includes('is_superadmin')) {
            if (!store.state.firm_permissions.includes('can_have_fire_contractors')) {
                 console.log('success page1')
                 next({
                    name: "page0"
                 })
             } else {
                 next()
             }
      }
      next()
    },
 }

我可以看到 console.log('success page1')next() 不工作...

next()之后添加return:

beforeEnter: (to, from, next) => {
     if (!store.state.roles.includes('is_superadmin')) {
            if (!store.state.firm_permissions.includes('can_have_fire_contractors')) {
                 console.log('success page1')
                 next({
                    name: "page0"
                 })
                 return // Add this
             } else {
                 next()
             }
      }
      next()
    },