@@ -7,7 +7,13 @@ import { buildHierarchyTree } from "@/utils/tree";
7
7
import remainingRouter from "./modules/remaining" ;
8
8
import { useMultiTagsStoreHook } from "@/store/modules/multiTags" ;
9
9
import { usePermissionStoreHook } from "@/store/modules/permission" ;
10
- import { isUrl , openLink , storageLocal , isAllEmpty } from "@pureadmin/utils" ;
10
+ import {
11
+ isUrl ,
12
+ openLink ,
13
+ cloneDeep ,
14
+ isAllEmpty ,
15
+ storageLocal
16
+ } from "@pureadmin/utils" ;
11
17
import {
12
18
ascending ,
13
19
getTopMenu ,
@@ -21,9 +27,9 @@ import {
21
27
} from "./utils" ;
22
28
import {
23
29
type Router ,
24
- createRouter ,
25
30
type RouteRecordRaw ,
26
- type RouteComponent
31
+ type RouteComponent ,
32
+ createRouter
27
33
} from "vue-router" ;
28
34
import {
29
35
type DataInfo ,
@@ -55,6 +61,9 @@ export const constantRoutes: Array<RouteRecordRaw> = formatTwoStageRoutes(
55
61
formatFlatteningRoutes ( buildHierarchyTree ( ascending ( routes . flat ( Infinity ) ) ) )
56
62
) ;
57
63
64
+ /** 初始的静态路由,用于退出登陆时重置路由 */
65
+ const initConstantRoutes : Array < RouteRecordRaw > = cloneDeep ( constantRoutes ) ;
66
+
58
67
/** 用于渲染菜单,保持原始层级 */
59
68
export const constantMenus : Array < RouteComponent > = ascending (
60
69
routes . flat ( Infinity )
@@ -87,17 +96,13 @@ export const router: Router = createRouter({
87
96
88
97
/** 重置路由 */
89
98
export function resetRouter ( ) {
90
- router . getRoutes ( ) . forEach ( route => {
91
- const { name, meta } = route ;
92
- if ( name && router . hasRoute ( name ) && meta ?. backstage ) {
93
- router . removeRoute ( name ) ;
94
- router . options . routes = formatTwoStageRoutes (
95
- formatFlatteningRoutes (
96
- buildHierarchyTree ( ascending ( routes . flat ( Infinity ) ) )
97
- )
98
- ) ;
99
- }
100
- } ) ;
99
+ router . clearRoutes ( ) ;
100
+ for ( const route of initConstantRoutes . concat ( ...( remainingRouter as any ) ) ) {
101
+ router . addRoute ( route ) ;
102
+ }
103
+ router . options . routes = formatTwoStageRoutes (
104
+ formatFlatteningRoutes ( buildHierarchyTree ( ascending ( routes . flat ( Infinity ) ) ) )
105
+ ) ;
101
106
usePermissionStoreHook ( ) . clearAllCachePage ( ) ;
102
107
}
103
108
1 commit comments
xiaoxian521 commentedon Apr 21, 2025