Files
kevisual-center/src/modules/basename.ts
2026-01-26 04:29:38 +08:00

27 lines
762 B
TypeScript

export const isDev = process.env.NODE_ENV === "development";
const BASE_NAME = isDev ? '' : '/root/center';
export const basename = BASE_NAME;
export const wrapBasename = (path: string) => {
const hasEnd = path.endsWith('/')
let _basename = basename;
if (basename) {
_basename = `${basename}${path}`;
} else {
_basename = path;
}
if (isDev) {
return _basename
}
return !hasEnd ? _basename + '/' : _basename;
}
export const openLink = (path: string, target: string = '_self') => {
if (path.startsWith('http://') || path.startsWith('https://')) {
window.open(path, target);
return;
}
const url = new URL(path, window.location.origin);
url.pathname = wrapBasename(url.pathname);
window.open(url.toString(), target);
}