Files
iten.pro/src/utils/paths.ts
Eduard Iten df6a0fa504
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 9s
Pfad-Problem behoben. Hoffe ich...
2026-03-31 12:41:13 +02:00

18 lines
620 B
TypeScript

// src/utils/paths.ts
// Wir greifen auf die Umgebungsvariable von Astro zu
const base = import.meta.env.BASE_URL;
/**
* Erstellt einen korrekten Pfad unter Berücksichtigung der Astro 'base' Konfiguration.
* Verhindert doppelte Slashes und funktioniert in Dev, Test und Prod.
*/
export function getPath(path: string): string {
// Entfernt den Slash am Ende der Base, falls vorhanden
const normalizedBase = base.replace(/\/$/, '');
// Stellt sicher, dass der Pfad mit einem Slash beginnt
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
return `${normalizedBase}${normalizedPath}`;
}