未验证 提交 02c469b1 编写于 作者: T Tanimodori 提交者: GitHub

types: 再次修复RouteLocationRawEx类型错误 (vbenjs#1968) (#1975)

上级 deff31bc
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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册