130 lines
2.6 KiB
JavaScript
130 lines
2.6 KiB
JavaScript
/*
|
||
* @Author: Kane
|
||
* @Date: 2022-12-14 15:12:46
|
||
* @LastEditors: Kane
|
||
* @LastEditTime: 2023-01-12 14:52:09
|
||
* @FilePath: \admin_system\src\router\index.js
|
||
* @Description: 定义应用路由配置
|
||
*
|
||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||
*/
|
||
import { createRouter, createWebHashHistory } from 'vue-router';
|
||
|
||
const routes = [
|
||
//框架路由
|
||
{
|
||
path: "/",
|
||
name: "Root",
|
||
redirect: "Login", //默认路由指向登录页面
|
||
hidden: true,
|
||
},
|
||
{
|
||
path: "/login",
|
||
name: "Login",
|
||
component: () => import("../views/account/Login.vue"),
|
||
hidden: true,
|
||
},
|
||
{
|
||
path: "/home",
|
||
name: "Home",
|
||
hidden: true,
|
||
meta: {
|
||
title: "控制台"
|
||
},
|
||
component: () => import("../layout/Index.vue"),
|
||
},
|
||
//侧边导航栏路由
|
||
{ //首页
|
||
path: "/console",
|
||
name: "Console",
|
||
meta: {
|
||
title: "总览",
|
||
icon: "house",
|
||
},
|
||
children: [
|
||
{
|
||
path: "/desktop",
|
||
name: "DeskTop",
|
||
meta: {
|
||
title: "工作台",
|
||
icon: "house",
|
||
},
|
||
component: () => import("../views/overview/OverView.vue"),
|
||
},
|
||
],
|
||
component: () => import("../layout/Index.vue"),
|
||
},
|
||
{//信息管理
|
||
path: "/news",
|
||
name: "News",
|
||
meta: {
|
||
title: "信息管理",
|
||
icon: "edit",
|
||
},
|
||
children: [
|
||
{
|
||
path: "/staffInfo",
|
||
name: "StaffInfo",
|
||
meta: {
|
||
title: "人员信息",
|
||
icon: "edit",
|
||
},
|
||
component: () => import("../views/info/StaffInfo.vue"),
|
||
},
|
||
{
|
||
path: "/newsIndex",
|
||
name: "NewsIndex",
|
||
meta: {
|
||
title: "信息列表",
|
||
icon: "edit",
|
||
},
|
||
component: () => import("../views/news/News.vue"),
|
||
},
|
||
{
|
||
path: "/newsedit",
|
||
name: "NewsEdit",
|
||
meta: {
|
||
title: "信息编辑",
|
||
icon: "edit",
|
||
},
|
||
component: () => import("../views/news/NewsEdit.vue"),
|
||
},
|
||
],
|
||
component: () => import("../layout/Index.vue"),
|
||
},
|
||
{
|
||
path: "/user",
|
||
name: "User",
|
||
meta: {
|
||
title: "人员管理",
|
||
icon: "edit",
|
||
},
|
||
component: () => import("../layout/Index.vue"),
|
||
},
|
||
];
|
||
|
||
const router = createRouter({
|
||
history: createWebHashHistory(),
|
||
routes
|
||
});
|
||
|
||
//前置路由守卫
|
||
router.beforeEach((to) =>
|
||
{
|
||
const token = window.localStorage.getItem("token");
|
||
|
||
if (!token)
|
||
{
|
||
//如果token不存在,判断路由是否走向login,如果不是则指向login
|
||
//走向login则不干预
|
||
if (to.name !== "Login")
|
||
{
|
||
return {
|
||
name: "Login",
|
||
};
|
||
}
|
||
}
|
||
});
|
||
|
||
export default router;
|