import { createRouter, createWebHashHistory } from 'vue-router' import { ElMessageBox, ElMessage } from 'element-plus' import LeftLayout from "@/views/LeftLayout" const routes = [{ path: "/left", name: 'left', component: LeftLayout, children: [ { meta: { action: "menuList", title: '权限菜单' }, path: 'menuList', name: 'menuList', component: () => import ('@views/menu/index.vue') }, { meta: { action: "roleList", title: '权限菜单' }, path: 'roleList', name: 'roleList', component: () => import ('@views/role/index.vue') }, { meta: { action: "websiteList", title: '站点列表' }, path: 'websiteList', name: 'websiteList', component: () => import ('@views/website/index.vue') }, ] }, //====================================== { meta: { action: "login", title: '登录', activity: true, requireAuth:false }, path: '/login', name: 'login', component: () => import ('@views/login/index.vue') } ] const router = createRouter({ history: createWebHashHistory(), routes }) const getCookie = function(objName) { //获取指定名称的cookie的值 var arrStr = document.cookie.split("; "); for (var i = 0; i < arrStr.length; i++) { var temp = arrStr[i].split("="); if (temp[0] == objName) return unescape(temp[1]); //解码 } return ""; } router.beforeEach((to, from) => { if(to.meta.requireAuth){ if(!document.getCookie("token")){ router.push('/login'); } } }) router.afterEach((to, from) => { if (to.meta && to.meta.title) { document.title = to.meta.title } }) export default router