猿问

vuex+全局路由钩子 怎么实现路由跳转拦截?

**我想模拟一个路由拦截判断登陆状态true的话就正常跳转,false就跳转到登陆页面但是报错好像进入了死循环我感觉逻辑没问题啊求大神开导开导哪里出了问题**
//main.js
importVuefrom'vue'
importAppfrom'./App'
importrouterfrom'./router'
importstorefrom'./vuex/store'
Vue.config.productionTip=false
router.beforeEach((to,from,next)=>{
store.state.islogin?next():next('/log')
})
//store
importVuefrom'vue'
importVuexfrom'vuex'
Vue.use(Vuex);
conststate={
islogin:false
}
HUX布斯
浏览 1328回答 2
2回答

噜噜哒

router.beforeEach((to,from,next)=>{if(to.meta.Auth){if(store.state.islogin){next();}else{router.push({name:'login'})}}else{next();}})路由{path:'/admin',name:'admin',meta:{Auth:true,//需要登录},component:Admin('admin')}

手掌心

router.beforeEach((to,from,next)=>{(store.state.islogin||to.path=='/log')?next():next('/log')})
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答