@@ -12,6 +12,40 @@ import { usePermissionStoreWithOut } from '@/store/modules/permission'
1212const { start, done } = useNProgress ( )
1313
1414const { 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+
1549// 路由不重定向白名单
1650const whiteList = [
1751 '/login' ,
@@ -47,8 +81,10 @@ router.beforeEach(async (to, from, next) => {
4781 router . addRoute ( route as unknown as RouteRecordRaw ) // 动态添加可访问路由表
4882 } )
4983 const redirectPath = from . query . redirect || to . path
84+ // 修复跳转时不带参数的问题
5085 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 }
5288 next ( nextData )
5389 } else {
5490 next ( )
0 commit comments