mirror of
https://github.com/vbenjs/vben-admin-thin-next.git
synced 2025-02-02 18:08:40 +08:00
fix: fixed useRedo
may loss route params
修复useRedo会丢失当前路由的params数据问题 fixed: #1079
This commit is contained in:
parent
da12da9d8c
commit
2dd3d85448
@ -17,6 +17,7 @@
|
|||||||
- 修复在`editComponentProps`中为编辑组件提供的`size`属性无效的问题
|
- 修复在`editComponentProps`中为编辑组件提供的`size`属性无效的问题
|
||||||
- **Qrcode** 修复二维码组件在创建时未能及时绘制的问题
|
- **Qrcode** 修复二维码组件在创建时未能及时绘制的问题
|
||||||
- **BasicModal** 修复`helpMessage`属性不起作用的问题
|
- **BasicModal** 修复`helpMessage`属性不起作用的问题
|
||||||
|
- **其它** 修复`useRedo`(重新加载当前路由)会丢失路由`params`数据的问题
|
||||||
|
|
||||||
## 2.7.0(2021-08-03)
|
## 2.7.0(2021-08-03)
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@
|
|||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
unref(isFixedHeightPage) &&
|
unref(isFixedHeightPage) &&
|
||||||
props.canResize &&
|
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);
|
const { getLoading, setLoading } = useLoading(getProps);
|
||||||
|
@ -5,6 +5,7 @@ import { isString } from '/@/utils/is';
|
|||||||
import { unref } from 'vue';
|
import { unref } from 'vue';
|
||||||
|
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
import { REDIRECT_NAME } from '/@/router/constant';
|
||||||
|
|
||||||
export type RouteLocationRawEx = Omit<RouteLocationRaw, 'path'> & { path: PageEnum };
|
export type RouteLocationRawEx = Omit<RouteLocationRaw, 'path'> & { path: PageEnum };
|
||||||
|
|
||||||
@ -37,19 +38,18 @@ export function useGo(_router?: Router) {
|
|||||||
* @description: redo current page
|
* @description: redo current page
|
||||||
*/
|
*/
|
||||||
export const useRedo = (_router?: Router) => {
|
export const useRedo = (_router?: Router) => {
|
||||||
let router;
|
const { push, currentRoute } = _router || useRouter();
|
||||||
if (!_router) {
|
const { query, params = {}, name, fullPath } = unref(currentRoute.value);
|
||||||
router = useRouter();
|
|
||||||
}
|
|
||||||
const { push, currentRoute } = _router || router;
|
|
||||||
const { query, params } = currentRoute.value;
|
|
||||||
function redo(): Promise<boolean> {
|
function redo(): Promise<boolean> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
push({
|
if (name && Object.keys(params).length > 0) {
|
||||||
path: '/redirect' + unref(currentRoute).fullPath,
|
params['_redirect_type'] = 'name';
|
||||||
query,
|
params['path'] = String(name);
|
||||||
params,
|
} else {
|
||||||
}).then(() => resolve(true));
|
params['_redirect_type'] = 'path';
|
||||||
|
params['path'] = fullPath;
|
||||||
|
}
|
||||||
|
push({ name: REDIRECT_NAME, params, query }).then(() => resolve(true));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return redo;
|
return redo;
|
||||||
|
@ -33,8 +33,8 @@ export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
|
|||||||
|
|
||||||
export const REDIRECT_ROUTE: AppRouteRecordRaw = {
|
export const REDIRECT_ROUTE: AppRouteRecordRaw = {
|
||||||
path: '/redirect',
|
path: '/redirect',
|
||||||
name: REDIRECT_NAME,
|
|
||||||
component: LAYOUT,
|
component: LAYOUT,
|
||||||
|
name: 'RedirectTo',
|
||||||
meta: {
|
meta: {
|
||||||
title: REDIRECT_NAME,
|
title: REDIRECT_NAME,
|
||||||
hideBreadcrumb: true,
|
hideBreadcrumb: true,
|
||||||
|
@ -8,12 +8,23 @@
|
|||||||
const { currentRoute, replace } = useRouter();
|
const { currentRoute, replace } = useRouter();
|
||||||
|
|
||||||
const { params, query } = unref(currentRoute);
|
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;
|
const _path = Array.isArray(path) ? path.join('/') : path;
|
||||||
|
|
||||||
replace({
|
if (_redirect_type === 'name') {
|
||||||
path: '/' + _path,
|
replace({
|
||||||
query,
|
name: _path,
|
||||||
});
|
query,
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
replace({
|
||||||
|
path: _path.startsWith('/') ? _path : '/' + _path,
|
||||||
|
query,
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user