diff --git a/src/modules/basename.ts b/src/modules/basename.ts index 0516610..4792606 100644 --- a/src/modules/basename.ts +++ b/src/modules/basename.ts @@ -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); } \ No newline at end of file