refactor: 拆分并调整路由守卫,优化顶部进度条展示

This commit is contained in:
2024-11-21 22:47:54 +08:00
parent 246d638a8f
commit e8941adde4
6 changed files with 113 additions and 100 deletions

View File

@@ -1,94 +1,10 @@
import { type RouteRecordRaw, createRouter, createWebHistory } from 'vue-router'
import { createRouter, createWebHistory } from 'vue-router'
import { useRouteStore } from '@/stores'
/** 默认布局 */
const Layout = () => import('@/layout/index.vue')
/** 静态路由 */
export const constantRoutes: RouteRecordRaw[] = [
{
path: '/redirect',
component: Layout,
meta: { hidden: true },
children: [
{
path: '/redirect/:path(.*)',
component: () => import('@/views/default/redirect/index.vue'),
},
],
},
{
path: '/login',
name: 'Login',
component: () => import('@/views/login/index.vue'),
meta: { hidden: true },
},
{
path: '/:pathMatch(.*)*',
component: () => import('@/views/default/error/404.vue'),
meta: { hidden: true },
},
{
path: '/403',
component: () => import('@/views/default/error/403.vue'),
meta: { hidden: true },
},
{
path: '/',
name: 'Dashboard',
component: Layout,
redirect: '/dashboard/workplace',
meta: { title: '仪表盘', icon: 'dashboard', hidden: false },
children: [
{
path: '/dashboard/workplace',
name: 'Workplace',
component: () => import('@/views/dashboard/workplace/index.vue'),
meta: { title: '工作台', icon: 'desktop', hidden: false, affix: true },
},
{
path: '/dashboard/analysis',
name: 'Analysis',
component: () => import('@/views/dashboard/analysis/index.vue'),
meta: { title: '分析页', icon: 'insert-chart', hidden: false },
},
],
},
{
path: '/social/callback',
component: () => import('@/views/login/social/index.vue'),
meta: { hidden: true },
},
{
path: '/pwdExpired',
component: () => import('@/views/login/pwdExpired/index.vue'),
meta: { hidden: true },
},
{
path: '/setting',
name: 'Setting',
component: Layout,
meta: { hidden: true },
children: [
{
path: '/setting/profile',
name: 'SettingProfile',
component: () => import('@/views/setting/profile/index.vue'),
meta: { title: '个人中心', showInTabs: false },
},
{
path: '/setting/message',
name: 'SettingMessage',
component: () => import('@/views/setting/message/index.vue'),
meta: { title: '消息中心', showInTabs: false },
},
],
},
]
import { constantRoutes, systemRoutes } from '@/router/route'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: constantRoutes,
routes: [...constantRoutes, ...systemRoutes],
scrollBehavior: () => ({ left: 0, top: 0 }),
})