新增 openLink 函数以处理外部链接和动态路径
This commit is contained in:
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user