From 75ea3805709e56ea023113e3c68d54f38d2307ff Mon Sep 17 00:00:00 2001 From: abearxiong Date: Wed, 11 Mar 2026 01:57:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20openLink=20=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E4=BB=A5=E5=A4=84=E7=90=86=E5=A4=96=E9=83=A8=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E5=92=8C=E5=8A=A8=E6=80=81=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/basename.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) 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