From 7eadf88ad50ee03d4d8b88b27eb4ac9ae2e2db94 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sun, 28 Sep 2025 04:17:49 +0300 Subject: [PATCH] Implement dynamic router base path retrieval for improved routing --- src/index.tsx | 3 ++- src/utils/paths.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.tsx b/src/index.tsx index 68af126..8ddfddb 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -5,6 +5,7 @@ import "./index.css"; import configureStore from "./redux/configureStore"; import { Provider as ReduxProvider } from "react-redux"; import "./utils/i18n"; +import { getRouterBasePath } from "./utils/paths"; const store = configureStore(); @@ -17,7 +18,7 @@ const root = createRoot(container); root.render( - + diff --git a/src/utils/paths.ts b/src/utils/paths.ts index c95cb62..20b606c 100644 --- a/src/utils/paths.ts +++ b/src/utils/paths.ts @@ -14,3 +14,12 @@ export const getPublicPath = (path: string): string => { const normalizedBase = basePath.endsWith("/") ? basePath : `${basePath}/`; return `${normalizedBase}${cleanPath}`; }; + +export const getRouterBasePath = (): string | undefined => { + const basePath = getBasePath(); + if (basePath === "/") return undefined; + // Remove trailing slash if present and ensure it starts with a slash + let baseUrl = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath; + baseUrl = baseUrl.startsWith("/") ? baseUrl : `/${baseUrl}`; + return baseUrl; +};