mirror of
https://dev.azure.com/tstanciu94/ReverseProxy/_git/ReverseProxy_Frontend
synced 2025-10-03 16:49:04 +03:00
Implement dynamic router base path retrieval for improved routing
This commit is contained in:
parent
7fa660eb71
commit
7eadf88ad5
@ -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(
|
||||
<ReduxProvider store={store}>
|
||||
<Router basename={import.meta.env.BASE_URL}>
|
||||
<Router basename={getRouterBasePath()}>
|
||||
<App />
|
||||
</Router>
|
||||
</ReduxProvider>
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user