Pfad-Problem behoben. Hoffe ich...
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 9s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 9s
This commit is contained in:
18
src/utils/paths.ts
Normal file
18
src/utils/paths.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
// 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}`;
|
||||
}
|
||||
Reference in New Issue
Block a user