From 53bb961a925cbafe53730450c5b069e255b54e03 Mon Sep 17 00:00:00 2001 From: hangzou <1102639563@qq.com> Date: Fri, 2 Jul 2021 17:19:31 +0800 Subject: [PATCH] fix: skip external URLs in `withBase` (#328) --- src/client/app/utils.ts | 6 ++++-- src/shared/shared.ts | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/client/app/utils.ts b/src/client/app/utils.ts index f6438cc1..4879f7ab 100644 --- a/src/client/app/utils.ts +++ b/src/client/app/utils.ts @@ -1,5 +1,5 @@ import { siteDataRef } from './data' -import { inBrowser } from '../shared' +import { inBrowser, EXTERNAL_URL_RE } from '../shared' export { inBrowser } @@ -11,7 +11,9 @@ export function joinPath(base: string, path: string): string { } export function withBase(path: string) { - return joinPath(siteDataRef.value.base, path) + return EXTERNAL_URL_RE.test(path) + ? path + : joinPath(siteDataRef.value.base, path) } /** diff --git a/src/shared/shared.ts b/src/shared/shared.ts index c7ce172c..302fa312 100644 --- a/src/shared/shared.ts +++ b/src/shared/shared.ts @@ -8,6 +8,8 @@ export type { Header } from '../../types/shared' +export const EXTERNAL_URL_RE = /^https?:/i + export const inBrowser = typeof window !== 'undefined' function findMatchRoot(route: string, roots: string[]) {