Commit f4a8e732 authored by chenqikuai's avatar chenqikuai

feat:添加路由权限控制

parent 2e27d560
import { token } from '@/util/userInfoUtils'
import Vue from 'vue' import Vue from 'vue'
import VueRouter, { RouteConfig } from 'vue-router' import VueRouter, { RouteConfig } from 'vue-router'
import App from '../App.vue' import App from '../App.vue'
...@@ -36,24 +37,27 @@ const routes: Array<RouteConfig> = [ ...@@ -36,24 +37,27 @@ const routes: Array<RouteConfig> = [
name: 'Login', name: 'Login',
component: () => import("@/view/Auth/Login/index.vue") component: () => import("@/view/Auth/Login/index.vue")
}, },
{ // {
path: '/auth/PwdSetting', // path: '/auth/PwdSetting',
name: 'PwdSetting', // name: 'PwdSetting',
component: () => import("@/view/Auth/PwdSetting/index.vue") // component: () => import("@/view/Auth/PwdSetting/index.vue")
}, // },
{ // {
path: '/auth/PwdFind', // path: '/auth/PwdFind',
name: 'PwdFind', // name: 'PwdFind',
component: () => import("@/view/Auth/PwdFind/index.vue") // component: () => import("@/view/Auth/PwdFind/index.vue")
}, // },
{ // {
path: '/auth/PwdModify', // path: '/auth/PwdModify',
name: 'PwdModify', // name: 'PwdModify',
component: () => import("@/view/Auth/PwdModify/index.vue") // component: () => import("@/view/Auth/PwdModify/index.vue")
}, // },
] ]
},
{
path: '*',
redirect: { name: 'Home' }
} }
] ]
...@@ -64,4 +68,12 @@ const router = new VueRouter({ ...@@ -64,4 +68,12 @@ const router = new VueRouter({
routes routes
}) })
router.beforeEach((to, from, next) => {
if (to.name !== 'Login' && token.getToken() === null) {
next({ name: 'Login' })
} else {
next()
}
})
export default router export default router
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