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 { PageEnum } from '/@/enums/pageEnum';
|
||||
import { isString } from '/@/utils/is';
|
||||
import { unref } from 'vue';
|
||||
|
||||
import { useRouter } from 'vue-router';
|
||||
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) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
// page switch
|
||||
/**
|
||||
* page switch
|
||||
*/
|
||||
export function useGo(_router?: Router) {
|
||||
let router;
|
||||
if (!_router) {
|
||||
router = useRouter();
|
||||
}
|
||||
const { push, replace } = _router || router;
|
||||
function go(opt: PageEnum | RouteLocationRawEx | string = PageEnum.BASE_HOME, isReplace = false) {
|
||||
const { push, replace } = _router || useRouter();
|
||||
function go(opt: RouteLocationRawEx = PageEnum.BASE_HOME, isReplace = false) {
|
||||
if (!opt) {
|
||||
return;
|
||||
}
|
||||
if (isString(opt)) {
|
||||
isReplace ? replace(opt).catch(handleError) : push(opt).catch(handleError);
|
||||
} else {
|
||||
const o = opt as RouteLocationRaw;
|
||||
isReplace ? replace(o).catch(handleError) : push(o).catch(handleError);
|
||||
}
|
||||
isReplace ? replace(opt).catch(handleError) : push(opt).catch(handleError);
|
||||
}
|
||||
return go;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user