import { createRouter, createWebHashHistory, RouteLocationNormalized, RouteRecordRaw, } from "vue-router"; 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 }, }, { path: "/", component: Layout, redirect: "/dashboard/index", children: [ { path: "401", component: () => import("@/views/error-page/401.vue"), meta: { hidden: true }, }, { path: "404", component: () => import("@/views/error-page/404.vue"), meta: { hidden: true }, }, ], }, ]; export const asyncRoutes: any[] = [ { path: "/dashboard", component: "Layout", redirect: "/dashboard/index", name: "Dashboard", meta: { title: "dashboard", icon: "report", roles: ["admin"], }, children: [ { path: "index", component: "dashboard/index", name: "DashboardIndex", meta: { title: "dashboard", icon: "report", roles: ["admin"], }, }, ], }, { path: "/admin", component: "Layout", redirect: "/admin/change-password", meta: { hidden: true, roles: ["admin"] }, children: [ { path: "change-password", component: "admin/change-password/index", name: "AdminChangePassword", meta: { title: "changePassword", hidden: true, roles: ["admin"] }, }, ], }, { path: "/peers", component: "Layout", redirect: "/peers/list", name: "Peer", meta: { title: "peer", icon: "users", roles: ["admin"] }, children: [ { path: "list", component: "peer/list/index", name: "PeerList", meta: { title: "peerList", icon: "users", roles: ["admin"], }, props: (route: RouteLocationNormalized) => ({ focus: route.query.focus, }), }, ], }, { path: "/hysteria", component: "Layout", redirect: "/hysteria/list", name: "Hysteria", meta: { title: "hysteria", icon: "hysteria", roles: ["admin"] }, children: [ { path: "list", component: "hysteria/list/index", name: "HysteriaList", meta: { title: "hysteriaList", icon: "hysteria", roles: ["admin"], }, }, ], }, { path: "/config", component: "Layout", redirect: "/config/list", name: "Config", meta: { title: "config", icon: "setting", roles: ["admin"] }, children: [ { path: "list", component: "config/list/index", name: "ConfigList", meta: { title: "configList", icon: "setting", roles: ["admin"], }, props: (route: RouteLocationNormalized) => ({ focus: route.query.focus, }), }, ], }, { path: "/log", component: "Layout", redirect: "/log/system", name: "Log", meta: { title: "log", icon: "error", roles: ["admin"] }, children: [ { path: "system", component: "log/system/index", name: "LogSystem", meta: { title: "logSystem", icon: "log-system", roles: ["admin"], }, }, { path: "hysteria", component: "log/hysteria/index", name: "LogHysteria", meta: { title: "logHysteria", icon: "log-hysteria", roles: ["admin"], }, }, ], }, ]; /** * Создание маршрутизатора */ const router = createRouter({ history: createWebHashHistory(), routes: constantRoutes as RouteRecordRaw[], // Восстановление позиции прокрутки при обновлении scrollBehavior: () => ({ left: 0, top: 0 }), }); /** * Сброс маршрутов */ export function resetRouter() { router.replace({ path: "/login" }); location.reload(); } export default router;