Commit 2dd3d8544866231895d23dba63785b683ae0062e
1 parent
da12da9d
fix: fixed `useRedo` may loss route params
修复useRedo会丢失当前路由的params数据问题 fixed: #1079
Showing
5 changed files
with
30 additions
and
18 deletions
CHANGELOG.zh_CN.md
src/components/Table/src/BasicTable.vue
... | ... | @@ -110,7 +110,7 @@ |
110 | 110 | watchEffect(() => { |
111 | 111 | unref(isFixedHeightPage) && |
112 | 112 | props.canResize && |
113 | - warn("[BasicTable] 'canRize' not worked with PageWrapper while 'fixedHeight' is true"); | |
113 | + warn("[BasicTable] 'canResize' may not worked in PageWrapper with 'fixedHeight'"); | |
114 | 114 | }); |
115 | 115 | |
116 | 116 | const { getLoading, setLoading } = useLoading(getProps); | ... | ... |
src/hooks/web/usePage.ts
... | ... | @@ -5,6 +5,7 @@ import { isString } from '/@/utils/is'; |
5 | 5 | import { unref } from 'vue'; |
6 | 6 | |
7 | 7 | import { useRouter } from 'vue-router'; |
8 | +import { REDIRECT_NAME } from '/@/router/constant'; | |
8 | 9 | |
9 | 10 | export type RouteLocationRawEx = Omit<RouteLocationRaw, 'path'> & { path: PageEnum }; |
10 | 11 | |
... | ... | @@ -37,19 +38,18 @@ export function useGo(_router?: Router) { |
37 | 38 | * @description: redo current page |
38 | 39 | */ |
39 | 40 | export const useRedo = (_router?: Router) => { |
40 | - let router; | |
41 | - if (!_router) { | |
42 | - router = useRouter(); | |
43 | - } | |
44 | - const { push, currentRoute } = _router || router; | |
45 | - const { query, params } = currentRoute.value; | |
41 | + const { push, currentRoute } = _router || useRouter(); | |
42 | + const { query, params = {}, name, fullPath } = unref(currentRoute.value); | |
46 | 43 | function redo(): Promise<boolean> { |
47 | 44 | return new Promise((resolve) => { |
48 | - push({ | |
49 | - path: '/redirect' + unref(currentRoute).fullPath, | |
50 | - query, | |
51 | - params, | |
52 | - }).then(() => resolve(true)); | |
45 | + if (name && Object.keys(params).length > 0) { | |
46 | + params['_redirect_type'] = 'name'; | |
47 | + params['path'] = String(name); | |
48 | + } else { | |
49 | + params['_redirect_type'] = 'path'; | |
50 | + params['path'] = fullPath; | |
51 | + } | |
52 | + push({ name: REDIRECT_NAME, params, query }).then(() => resolve(true)); | |
53 | 53 | }); |
54 | 54 | } |
55 | 55 | return redo; | ... | ... |
src/router/routes/basic.ts
... | ... | @@ -33,8 +33,8 @@ export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = { |
33 | 33 | |
34 | 34 | export const REDIRECT_ROUTE: AppRouteRecordRaw = { |
35 | 35 | path: '/redirect', |
36 | - name: REDIRECT_NAME, | |
37 | 36 | component: LAYOUT, |
37 | + name: 'RedirectTo', | |
38 | 38 | meta: { |
39 | 39 | title: REDIRECT_NAME, |
40 | 40 | hideBreadcrumb: true, | ... | ... |
src/views/sys/redirect/index.vue
... | ... | @@ -8,12 +8,23 @@ |
8 | 8 | const { currentRoute, replace } = useRouter(); |
9 | 9 | |
10 | 10 | const { params, query } = unref(currentRoute); |
11 | - const { path } = params; | |
11 | + const { path, _redirect_type = 'path' } = params; | |
12 | + | |
13 | + Reflect.deleteProperty(params, '_redirect_type'); | |
14 | + Reflect.deleteProperty(params, 'path'); | |
12 | 15 | |
13 | 16 | const _path = Array.isArray(path) ? path.join('/') : path; |
14 | 17 | |
15 | - replace({ | |
16 | - path: '/' + _path, | |
17 | - query, | |
18 | - }); | |
18 | + if (_redirect_type === 'name') { | |
19 | + replace({ | |
20 | + name: _path, | |
21 | + query, | |
22 | + params, | |
23 | + }); | |
24 | + } else { | |
25 | + replace({ | |
26 | + path: _path.startsWith('/') ? _path : '/' + _path, | |
27 | + query, | |
28 | + }); | |
29 | + } | |
19 | 30 | </script> | ... | ... |