mirror of
https://github.com/vbenjs/gf-vben-admin.git
synced 2025-02-02 19:08:40 +08:00
types: 再次修复RouteLocationRawEx类型错误 (vbenjs#1968) (#1975)
This commit is contained in:
parent
5af13e92f5
commit
369f0f025e
@ -1,35 +1,28 @@
|
|||||||
import type { RouteLocationRaw, Router } from 'vue-router';
|
import type { RouteLocationRaw, Router } from 'vue-router';
|
||||||
|
|
||||||
import { PageEnum } from '/@/enums/pageEnum';
|
import { PageEnum } from '/@/enums/pageEnum';
|
||||||
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';
|
import { REDIRECT_NAME } from '/@/router/constant';
|
||||||
|
|
||||||
export type RouteLocationRawEx = RouteLocationRaw & { path: PageEnum };
|
export type PathAsPageEnum<T> = T extends { path: string } ? T & { path: PageEnum } : T;
|
||||||
|
export type RouteLocationRawEx = PathAsPageEnum<RouteLocationRaw>;
|
||||||
|
|
||||||
function handleError(e: Error) {
|
function handleError(e: Error) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// page switch
|
/**
|
||||||
|
* page switch
|
||||||
|
*/
|
||||||
export function useGo(_router?: Router) {
|
export function useGo(_router?: Router) {
|
||||||
let router;
|
const { push, replace } = _router || useRouter();
|
||||||
if (!_router) {
|
function go(opt: RouteLocationRawEx = PageEnum.BASE_HOME, isReplace = false) {
|
||||||
router = useRouter();
|
|
||||||
}
|
|
||||||
const { push, replace } = _router || router;
|
|
||||||
function go(opt: PageEnum | RouteLocationRawEx | string = PageEnum.BASE_HOME, isReplace = false) {
|
|
||||||
if (!opt) {
|
if (!opt) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isString(opt)) {
|
isReplace ? replace(opt).catch(handleError) : push(opt).catch(handleError);
|
||||||
isReplace ? replace(opt).catch(handleError) : push(opt).catch(handleError);
|
|
||||||
} else {
|
|
||||||
const o = opt as RouteLocationRaw;
|
|
||||||
isReplace ? replace(o).catch(handleError) : push(o).catch(handleError);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return go;
|
return go;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user