新增 openLink 函数以处理外部链接和动态路径

This commit is contained in:
2026-03-11 01:57:25 +08:00
parent a5c3b6e4e0
commit 75ea380570

View File

@@ -19,4 +19,14 @@ export const getDynamicBasename = (): string => {
}
// 默认使用构建时的 basename
return 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);
}