diff --git a/packages/qwik/src/core/platform/platform.ts b/packages/qwik/src/core/platform/platform.ts index 05f345da495..a718e861705 100644 --- a/packages/qwik/src/core/platform/platform.ts +++ b/packages/qwik/src/core/platform/platform.ts @@ -66,9 +66,9 @@ export const createPlatform = (): CorePlatform => { */ export const toUrl = (doc: Document, containerEl: QwikElement, url: string | URL): URL => { const baseURI = new URL(doc.baseURI); - const base = containerEl?.getAttribute('q:base') ?? '/'; - const pathUrl = (base + url).replace(/\/+/g, '/'); - return new URL(pathUrl, baseURI.origin); + const base = new URL(containerEl.getAttribute('q:base') ?? baseURI, baseURI); + const pathUrl = (base.pathname + url).replace(/\/+/g, '/'); + return new URL(pathUrl, base.origin); }; let _platform = /*#__PURE__ */ createPlatform(); diff --git a/packages/qwik/src/qwikloader.ts b/packages/qwik/src/qwikloader.ts index e7257a01f05..b27ddf1e9d6 100644 --- a/packages/qwik/src/qwikloader.ts +++ b/packages/qwik/src/qwikloader.ts @@ -73,10 +73,10 @@ export const qwikLoader = (doc: Document, hasInitialized?: number) => { if (attrValue) { const container = element.closest('[q\\:container]')!; const baseURI = new URL(doc.baseURI); - const base = container?.getAttribute('q:base') ?? '/'; + const base = new URL(container.getAttribute('q:base') ?? baseURI, baseURI); for (const qrl of attrValue.split('\n')) { - const pathUrl = (base + qrl).replace(/\/+/g, '/'); - const url = new URL(pathUrl, baseURI.origin); + const pathUrl = (base.pathname + qrl).replace(/\/+/g, '/'); + const url = new URL(pathUrl, base.origin); const symbolName = url.hash[replace](/^#?([^?[|]*).*$/, '$1') || 'default'; const reqTime = performance.now(); let handler: any; diff --git a/packages/qwik/src/testing/platform.ts b/packages/qwik/src/testing/platform.ts index 0b61b429558..167179cc2ab 100644 --- a/packages/qwik/src/testing/platform.ts +++ b/packages/qwik/src/testing/platform.ts @@ -97,9 +97,9 @@ export function setTestPlatform(_setPlatform: Function) { */ export function toUrl(doc: Document, containerEl: Element, url: string | URL): URL { const baseURI = new URL(doc.baseURI); - const base = containerEl?.getAttribute('q:base') ?? '/'; - const pathUrl = (base + url).replace(/\/+/g, '/'); - return new URL(pathUrl, baseURI.origin); + const base = new URL(containerEl.getAttribute('q:base') ?? baseURI, baseURI); + const pathUrl = (base.pathname + url).replace(/\/+/g, '/'); + return new URL(pathUrl, base.origin); } function toPath(url: URL) {