配置路由结构

This commit is contained in:
tao
2025-12-23 13:27:03 +08:00
parent 73dd0ae6b6
commit c9e442ef0c

View File

@@ -1,23 +1,63 @@
import { createRouter, createWebHistory } from 'vue-router';
import { getToken } from "@/utils/auth";
const whiteList = ["/login"];
const routes = [
{
path: '/',
name: 'Index',
component: () => import('@/views/index.vue')
},
{
path: '/login',
name: 'Login',
component: () => import('@/views/login.vue')
},
{
path: '/pwoManage',
name: 'PwoManage',
component: () => import('@/views/pwoManage/index.vue')
}
{
path: "/",
name: "Index",
component: () => import("@/views/index.vue"),
},
{
path: "/login",
name: "Login",
component: () => import("@/views/login.vue"),
},
{
path: "/pwoManage",
name: "PwoManage",
component: () => import("@/views/pwoManage/layout.vue"),
redirect: { name: "PwoManageIndex" },
children: [
{
path: "",
name: "PwoManageIndex",
component: () => import("@/views/pwoManage/index.vue"),
},
{
path: "infeed",
name: "Infeed",
component: () => import("@/views/pwoManage/infeed/layout.vue"),
redirect: { name: "PrimaryMaterial" },
children: [
{
path: "primaryMaterial",
name: "PrimaryMaterial",
component: () =>
import("@/views/pwoManage/infeed/primaryMaterial/index.vue"),
},
{
path: "rawMaterial",
name: "RawMaterial",
component: () =>
import("@/views/pwoManage/infeed/rawMaterial/index.vue"),
},
{
path: "fixture",
name: "Fixture",
component: () =>
import("@/views/pwoManage/infeed/fixture/index.vue"),
},
],
},
{
path: "outfeed",
name: "Outfeed",
component: () => import("@/views/pwoManage/outfeed/index.vue"),
},
],
},
];
const router = createRouter({
@@ -26,18 +66,17 @@ const router = createRouter({
});
router.beforeEach(async (to, from, next) => {
const token = localStorage.getItem("token");
const token = getToken();
// 已登录,访问 login → 跳首页
if (token && to.path === "/login") {
return next("/");
}
// 白名单放行
if (whiteList.includes(to.path)) {
return next();
}
// 已登录,访问 login → 跳首页
if (token && to.path === "/login") {
return next("/");
}
// 未登录,访问受保护路由
if (!token) {
return next({
@@ -50,4 +89,4 @@ router.beforeEach(async (to, from, next) => {
next();
});
export default router;
export default router;