Skip to content

Commit

Permalink
fix: fixed useRedo may loss route params
Browse files Browse the repository at this point in the history
修复useRedo会丢失当前路由的params数据问题

fixed: #1079
  • Loading branch information
mynetfan committed Aug 15, 2021
1 parent da12da9 commit 2dd3d85
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- 修复在`editComponentProps`中为编辑组件提供的`size`属性无效的问题
- **Qrcode** 修复二维码组件在创建时未能及时绘制的问题
- **BasicModal** 修复`helpMessage`属性不起作用的问题
- **其它** 修复`useRedo`(重新加载当前路由)会丢失路由`params`数据的问题

## 2.7.0(2021-08-03)

Expand Down
2 changes: 1 addition & 1 deletion src/components/Table/src/BasicTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
watchEffect(() => {
unref(isFixedHeightPage) &&
props.canResize &&
warn("[BasicTable] 'canRize' not worked with PageWrapper while 'fixedHeight' is true");
warn("[BasicTable] 'canResize' may not worked in PageWrapper with 'fixedHeight'");
});
const { getLoading, setLoading } = useLoading(getProps);
Expand Down
22 changes: 11 additions & 11 deletions src/hooks/web/usePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isString } from '/@/utils/is';
import { unref } from 'vue';

import { useRouter } from 'vue-router';
import { REDIRECT_NAME } from '/@/router/constant';

export type RouteLocationRawEx = Omit<RouteLocationRaw, 'path'> & { path: PageEnum };

Expand Down Expand Up @@ -37,19 +38,18 @@ export function useGo(_router?: Router) {
* @description: redo current page
*/
export const useRedo = (_router?: Router) => {
let router;
if (!_router) {
router = useRouter();
}
const { push, currentRoute } = _router || router;
const { query, params } = currentRoute.value;
const { push, currentRoute } = _router || useRouter();
const { query, params = {}, name, fullPath } = unref(currentRoute.value);
function redo(): Promise<boolean> {
return new Promise((resolve) => {
push({
path: '/redirect' + unref(currentRoute).fullPath,
query,
params,
}).then(() => resolve(true));
if (name && Object.keys(params).length > 0) {
params['_redirect_type'] = 'name';
params['path'] = String(name);
} else {
params['_redirect_type'] = 'path';
params['path'] = fullPath;
}
push({ name: REDIRECT_NAME, params, query }).then(() => resolve(true));
});
}
return redo;
Expand Down
2 changes: 1 addition & 1 deletion src/router/routes/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {

export const REDIRECT_ROUTE: AppRouteRecordRaw = {
path: '/redirect',
name: REDIRECT_NAME,
component: LAYOUT,
name: 'RedirectTo',
meta: {
title: REDIRECT_NAME,
hideBreadcrumb: true,
Expand Down
21 changes: 16 additions & 5 deletions src/views/sys/redirect/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,23 @@
const { currentRoute, replace } = useRouter();
const { params, query } = unref(currentRoute);
const { path } = params;
const { path, _redirect_type = 'path' } = params;
Reflect.deleteProperty(params, '_redirect_type');
Reflect.deleteProperty(params, 'path');
const _path = Array.isArray(path) ? path.join('/') : path;
replace({
path: '/' + _path,
query,
});
if (_redirect_type === 'name') {
replace({
name: _path,
query,
params,
});
} else {
replace({
path: _path.startsWith('/') ? _path : '/' + _path,
query,
});
}
</script>

0 comments on commit 2dd3d85

Please sign in to comment.