import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router"; import { getCurrentInstance } from "vue"; export const Layout = () => import("@/layout/index.vue"); // 静态路由 export const constantRoutes: RouteRecordRaw[] = [ // 登录 { path: "/login", component: () => import("@/views/login/index.vue"), meta: { hidden: true }, name: "login", }, { path: "/signSucceed", component: () => import("@/views/signSucceed/index.vue"), meta: { hidden: true }, }, { path: "/", component: Layout, redirect: "/model", children: [ { path: "model", component: () => import("@/views/mangage/model.vue"), name: "model", meta: { title: "model", icon: "homepage", affix: true, name: "modelMangage.title", }, }, ], }, { path: "/", component: Layout, redirect: "/keyCheck", children: [ { path: "keyCheck", component: () => import("@/views/mangage/keyCheck.vue"), name: "keyCheck", meta: { title: "keyCheck", icon: "homepage", affix: true, name: "keyMangage.title", }, }, ], }, // 系统设置路由 { path: "/", component: Layout, redirect: "/userList", children: [ { path: "userList", component: () => import("@/views/dict/index.vue"), name: "userList", meta: { title: "userList", icon: "homepage", affix: true, name: "userListMangage.title", }, }, ], }, { path: "/", component: Layout, redirect: "/ruleList", children: [ { path: "ruleList", component: () => import("@/views/mangage/ruleList.vue"), name: "ruleList", meta: { title: "ruleList", icon: "homepage", affix: true, name: "ruleListMangage.title", }, }, ], }, ]; /** * 创建路由 */ const router = createRouter({ history: createWebHashHistory(), routes: constantRoutes as RouteRecordRaw[], // 刷新时,滚动条位置还原 // 2023-5-23 添加平滑滚动 YWQ scrollBehavior: () => ({ behavior: "smooth", left: 0, top: 0 }), }); /** * 重置路由 */ export function resetRouter() { router.replace({ path: "/login" }); } export default router;