@@ -12,6 +12,40 @@ import { usePermissionStoreWithOut } from '@/store/modules/permission'
12
12
const { start, done } = useNProgress ( )
13
13
14
14
const { loadStart, loadDone } = usePageLoading ( )
15
+
16
+ const parseURL = (
17
+ url : string | null | undefined
18
+ ) : { basePath : string ; paramsObject : { [ key : string ] : string } } => {
19
+ // 如果输入为 null 或 undefined,返回空字符串和空对象
20
+ if ( url == null ) {
21
+ return { basePath : '' , paramsObject : { } }
22
+ }
23
+
24
+ // 找到问号 (?) 的位置,它之前是基础路径,之后是查询参数
25
+ const questionMarkIndex = url . indexOf ( '?' )
26
+ let basePath = url
27
+ const paramsObject : { [ key : string ] : string } = { }
28
+
29
+ // 如果找到了问号,说明有查询参数
30
+ if ( questionMarkIndex !== - 1 ) {
31
+ // 获取 basePath
32
+ basePath = url . substring ( 0 , questionMarkIndex )
33
+
34
+ // 从 URL 中获取查询字符串部分
35
+ const queryString = url . substring ( questionMarkIndex + 1 )
36
+
37
+ // 使用 URLSearchParams 遍历参数
38
+ const searchParams = new URLSearchParams ( queryString )
39
+ searchParams . forEach ( ( value , key ) => {
40
+ // 封装进 paramsObject 对象
41
+ paramsObject [ key ] = value
42
+ } )
43
+ }
44
+
45
+ // 返回 basePath 和 paramsObject
46
+ return { basePath, paramsObject }
47
+ }
48
+
15
49
// 路由不重定向白名单
16
50
const whiteList = [
17
51
'/login' ,
@@ -47,8 +81,10 @@ router.beforeEach(async (to, from, next) => {
47
81
router . addRoute ( route as unknown as RouteRecordRaw ) // 动态添加可访问路由表
48
82
} )
49
83
const redirectPath = from . query . redirect || to . path
84
+ // 修复跳转时不带参数的问题
50
85
const redirect = decodeURIComponent ( redirectPath as string )
51
- const nextData = to . path === redirect ? { ...to , replace : true } : { path : redirect }
86
+ const { basePath, paramsObject : query } = parseURL ( redirect )
87
+ const nextData = to . path === redirect ? { ...to , replace : true } : { path : redirect , query }
52
88
next ( nextData )
53
89
} else {
54
90
next ( )
0 commit comments