import { createRouter, createWebHistory } from 'vue-router' import { registerBeforeRouter, registerAfterRouter } from './guard' export const homeIndex = () => import('@/views/home/index.vue') export const Layout = () => import('@/layout/index.vue') import { routes as systemRoutes } from './modules/system' import { routes as userRoutes } from './modules/user' // 静态路由 export const constantRoutes = [ { path: '/redirect', component: Layout, meta: { hidden: true }, children: [ { path: '/redirect/:path(.*)', component: () => import('@/views/redirect/index.vue') } ] }, { path: '/login', name: 'Login', meta: { title: '系统登录' }, component: () => import('@/views/login/index.vue') }, { path: '/', name: 'Layout', component: Layout, children: [ { path: '/', name: 'home', meta: { title: '首页', affix: true, keepAlive: true, alwaysShow: false }, component: () => import('@/views/home/index.vue') }, { path: '401', component: () => import('@/views/error-page/401.vue'), meta: { hidden: true } }, { path: '404', component: () => import('@/views/error-page/404.vue'), meta: { hidden: true } }, ...systemRoutes, ...userRoutes, { path: '/acccount', name: 'acccount', meta: { title: '账号管理', affix: true, keepAlive: true, alwaysShow: false }, component: () => import('@/views/account/index.vue') } ] } ] /** * 创建路由 */ const router = createRouter({ history: createWebHistory(), routes: constantRoutes, // 刷新时,滚动条位置还原 scrollBehavior: () => ({ left: 0, top: 0 }) }) registerBeforeRouter(router) registerAfterRouter(router) export default router