diff --git a/apps/admin/app/compat/next/helper.ts b/apps/admin/app/compat/next/helper.ts index fe1a98446..c04699870 100644 --- a/apps/admin/app/compat/next/helper.ts +++ b/apps/admin/app/compat/next/helper.ts @@ -5,8 +5,10 @@ */ export function ensureTrailingSlash(url: string): string { try { - // Handle relative URLs by creating a URL object with a dummy base - const urlObj = new URL(url, "http://dummy.com"); + const fallbackBaseUrl = + typeof window !== "undefined" && window.location.origin ? window.location.origin : "http://dummy.com"; + // Handle relative URLs by creating a URL object with a fallback base URL + const urlObj = new URL(url, fallbackBaseUrl); // Don't modify root path if (urlObj.pathname === "/") { diff --git a/apps/space/app/compat/next/helper.ts b/apps/space/app/compat/next/helper.ts index fe1a98446..c04699870 100644 --- a/apps/space/app/compat/next/helper.ts +++ b/apps/space/app/compat/next/helper.ts @@ -5,8 +5,10 @@ */ export function ensureTrailingSlash(url: string): string { try { - // Handle relative URLs by creating a URL object with a dummy base - const urlObj = new URL(url, "http://dummy.com"); + const fallbackBaseUrl = + typeof window !== "undefined" && window.location.origin ? window.location.origin : "http://dummy.com"; + // Handle relative URLs by creating a URL object with a fallback base URL + const urlObj = new URL(url, fallbackBaseUrl); // Don't modify root path if (urlObj.pathname === "/") { diff --git a/apps/web/app/compat/next/helper.ts b/apps/web/app/compat/next/helper.ts index fe1a98446..c04699870 100644 --- a/apps/web/app/compat/next/helper.ts +++ b/apps/web/app/compat/next/helper.ts @@ -5,8 +5,10 @@ */ export function ensureTrailingSlash(url: string): string { try { - // Handle relative URLs by creating a URL object with a dummy base - const urlObj = new URL(url, "http://dummy.com"); + const fallbackBaseUrl = + typeof window !== "undefined" && window.location.origin ? window.location.origin : "http://dummy.com"; + // Handle relative URLs by creating a URL object with a fallback base URL + const urlObj = new URL(url, fallbackBaseUrl); // Don't modify root path if (urlObj.pathname === "/") {