xto-fronted 0.4.42 → 0.4.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@
4
4
 
5
5
  import type { RouteRecordRaw } from 'vue-router'
6
6
 
7
- // 布局路由(包含默认子路由)
7
+ // 布局路由(包含默认子路由和 catch-all 404)
8
8
  export const layoutRoute: RouteRecordRaw = {
9
9
  path: '/',
10
10
  name: 'Layout',
@@ -51,6 +51,16 @@ export const layoutRoute: RouteRecordRaw = {
51
51
  icon: 'menu',
52
52
  keepAlive: true
53
53
  }
54
+ },
55
+ // catch-all 路由:让 404 在 Layout 内部渲染,保持左侧菜单显示
56
+ {
57
+ path: '/:pathMatch(.*)*',
58
+ name: 'CatchAll',
59
+ component: () => import('@/views/error/404.vue'),
60
+ meta: {
61
+ title: '404',
62
+ hidden: true
63
+ }
54
64
  }
55
65
  ]
56
66
  }
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import { createRouter, createWebHistory } from 'vue-router'
6
- import { staticRoutes, errorRoute } from './staticRoutes'
6
+ import { staticRoutes } from './staticRoutes'
7
7
  import { layoutRoute } from './dynamicRoutes'
8
8
  import { hasToken } from '@/utils/auth'
9
9
  import { getAppId } from '@/utils/config'
@@ -14,12 +14,12 @@ import { mockMenuData } from './dynamicRoutes'
14
14
 
15
15
  const router = createRouter({
16
16
  history: createWebHistory(),
17
- routes: [...staticRoutes, layoutRoute, errorRoute],
17
+ routes: [...staticRoutes, layoutRoute],
18
18
  scrollBehavior: () => ({ left: 0, top: 0 })
19
19
  })
20
20
 
21
21
  // 白名单路由
22
- const whiteList = ['/login', '/404', '/403']
22
+ const whiteList = ['/login']
23
23
 
24
24
  // 路由守卫
25
25
  router.beforeEach(async (to, _from, next) => {
@@ -72,7 +72,7 @@ router.beforeEach(async (to, _from, next) => {
72
72
  export function resetRouter() {
73
73
  const newRouter = createRouter({
74
74
  history: createWebHistory(),
75
- routes: [...staticRoutes, layoutRoute, errorRoute]
75
+ routes: [...staticRoutes, layoutRoute]
76
76
  })
77
77
  ;(router as any).matcher = (newRouter as any).matcher
78
78
  }
@@ -22,12 +22,22 @@ export function createLayoutRoute(
22
22
  ): RouteRecordRaw {
23
23
  const indexPath = options.indexPath || '/dashboard'
24
24
 
25
+ // 添加 catch-all 路由,让404在Layout内部渲染,保持左侧菜单显示
26
+ const catchAllRoute: RouteRecordRaw = {
27
+ path: '/:pathMatch(.*)*',
28
+ name: 'CatchAll',
29
+ component: () => import('@/views/error/404.vue'),
30
+ meta: {
31
+ title: '404'
32
+ }
33
+ }
34
+
25
35
  return {
26
36
  path: '/',
27
37
  name: 'Layout',
28
38
  component: Layout,
29
39
  redirect: indexPath,
30
- children
40
+ children: [...children, catchAllRoute]
31
41
  }
32
42
  }
33
43
 
@@ -13,31 +13,7 @@ export const staticRoutes: RouteRecordRaw[] = [
13
13
  title: '登录',
14
14
  hidden: true
15
15
  }
16
- },
17
- {
18
- path: '/404',
19
- name: 'NotFound',
20
- component: () => import('@/views/error/404.vue'),
21
- meta: {
22
- title: '404',
23
- hidden: true
24
- }
25
- },
26
- {
27
- path: '/403',
28
- name: 'Forbidden',
29
- component: () => import('@/views/error/403.vue'),
30
- meta: {
31
- title: '403',
32
- hidden: true
33
- }
34
16
  }
35
17
  ]
36
18
 
37
- export const errorRoute: RouteRecordRaw = {
38
- path: '/:pathMatch(.*)*',
39
- redirect: '/404',
40
- meta: {
41
- hidden: true
42
- }
43
- }
19
+ // 注意:404 403 路由已在 layoutRoute.ts 的 catch-all 中处理,确保在 Layout 内部渲染