提交 2dd3d854 编写于 作者: 无木

fix: fixed `useRedo` may loss route params

修复useRedo会丢失当前路由的params数据问题

fixed: #1079
上级 da12da9d
......@@ -17,6 +17,7 @@
- 修复在`editComponentProps`中为编辑组件提供的`size`属性无效的问题
- **Qrcode** 修复二维码组件在创建时未能及时绘制的问题
- **BasicModal** 修复`helpMessage`属性不起作用的问题
- **其它** 修复`useRedo`(重新加载当前路由)会丢失路由`params`数据的问题
## 2.7.0(2021-08-03)
......
......@@ -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);
......
......@@ -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 };
......@@ -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;
......
......@@ -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,
......
......@@ -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>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册