2026-03-25 10:02:19 +08:00
|
|
|
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
|
|
|
|
|
import { usePermissionStoreHook } from '@/store/modules/permission';
|
|
|
|
|
|
|
|
|
|
export const Layout = () => import('@/layout/index.vue');
|
|
|
|
|
|
|
|
|
|
// 静态路由
|
|
|
|
|
export const constantRoutes: RouteRecordRaw[] = [
|
|
|
|
|
{
|
|
|
|
|
path: '/redirect',
|
|
|
|
|
component: Layout,
|
|
|
|
|
meta: { hidden: true },
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
path: '/redirect/:path(.*)',
|
|
|
|
|
component: () => import('@/views/redirect/index.vue')
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/login',
|
|
|
|
|
component: () => import('@/views/login/index.vue'),
|
|
|
|
|
meta: { hidden: true }
|
2026-04-21 14:42:10 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/login-sjtb',
|
|
|
|
|
component: () => import('@/views/login-sjtb/index.vue'),
|
|
|
|
|
meta: { hidden: true }
|
2026-03-25 10:02:19 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/404',
|
|
|
|
|
component: () => import('@/views/error-page/404.vue'),
|
|
|
|
|
meta: { hidden: true }
|
|
|
|
|
},
|
2026-03-27 14:50:35 +08:00
|
|
|
{
|
|
|
|
|
path: '/401',
|
|
|
|
|
component: () => import('@/views/error-page/401.vue'),
|
|
|
|
|
meta: { hidden: true }
|
|
|
|
|
},
|
2026-03-25 10:02:19 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// 创建路由
|
|
|
|
|
const router = createRouter({
|
|
|
|
|
history: createWebHashHistory(),
|
|
|
|
|
routes: constantRoutes as RouteRecordRaw[],
|
|
|
|
|
// 刷新时,滚动条位置还原
|
|
|
|
|
scrollBehavior: () => ({ left: 0, top: 0 })
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 重置路由
|
|
|
|
|
export function resetRouter() {
|
|
|
|
|
const permissionStore = usePermissionStoreHook();
|
|
|
|
|
permissionStore.routes.forEach(route => {
|
|
|
|
|
const name = route.name;
|
|
|
|
|
if (name && router.hasRoute(name)) {
|
|
|
|
|
router.hasRoute(name) && router.removeRoute(name);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default router;
|