fix: ignore cross-origin basename hints

This commit is contained in:
Johngenri
2026-03-08 16:01:26 +01:00
parent 92b468a39e
commit 1dd395fdd6

View File

@@ -38,7 +38,12 @@ function detectRouterBasename() {
let detectedBasename = ''; let detectedBasename = '';
for (const candidate of candidatePaths) { for (const candidate of candidatePaths) {
try { try {
const pathname = new URL(candidate.value, document.baseURI || window.location.href).pathname; const candidateUrl = new URL(candidate.value, document.baseURI || window.location.href);
if (candidateUrl.origin !== window.location.origin) {
continue;
}
const pathname = candidateUrl.pathname;
const normalizedPathname = pathname.replace(/\/+$/, ''); const normalizedPathname = pathname.replace(/\/+$/, '');
let normalized = ''; let normalized = '';
@@ -53,7 +58,7 @@ function detectRouterBasename() {
const match = candidate.kind === 'manifest' ? manifestMatch : iconMatch; const match = candidate.kind === 'manifest' ? manifestMatch : iconMatch;
if (match?.[1]) { if (match?.[1]) {
const segments = match[1].split('/').filter(Boolean); const segments = match[1].split('/').filter(Boolean);
while (segments.length > 0 && ['assets', 'static', 'icons', 'images'].includes(segments[segments.length - 1])) { while (segments.length > 1 && ['assets', 'static', 'icons', 'images'].includes(segments[segments.length - 1])) {
segments.pop(); segments.pop();
} }
normalized = segments.length > 0 ? `/${segments.join('/')}` : ''; normalized = segments.length > 0 ? `/${segments.join('/')}` : '';