Commit f626eca7 authored by lipengcheng 's avatar lipengcheng

feat: 优化router.beforeEach鉴权方法

parent 7b7fb5c8
import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store/index.js'
console.log('store:', store)
Vue.use(VueRouter)
......@@ -57,7 +56,7 @@ const router = new VueRouter({
// 路由全局前置守卫
router.beforeEach((to, from, next) => {
if (to.name !== 'page2' && !store.getters['authed']) next({ name: 'page2' })
if (to.meta.needAuth && !store.getters['authed']) next({ name: 'page2' })
else next()
})
......
export default {
path: '/page1',
name: 'Page1',
meta: {
needAuth: true
},
component: () => import(/* webpackChunkName: "page1" */ '../views/page1.vue')
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment