fix(main): update resolveRouterBasename function to return prefix instead of withSlash for improved routing behavior
This commit is contained in:
@@ -4,12 +4,6 @@ import { BrowserRouter } from "react-router-dom";
|
|||||||
import App from "./App.jsx";
|
import App from "./App.jsx";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
|
||||||
/**
|
|
||||||
* `import.meta.env.BASE_URL` es fijo en build (p. ej. `/orcid2words/` en prod).
|
|
||||||
* Los assets siguen bajo ese prefijo, pero la URL del documento puede ser `/`
|
|
||||||
* (acceso directo `http://host:8073/`). React Router exige que el pathname
|
|
||||||
* empiece por el basename; si no, no renderiza nada.
|
|
||||||
*/
|
|
||||||
function resolveRouterBasename() {
|
function resolveRouterBasename() {
|
||||||
const configured = import.meta.env.BASE_URL ?? "/";
|
const configured = import.meta.env.BASE_URL ?? "/";
|
||||||
const withSlash = configured.endsWith("/") ? configured : `${configured}/`;
|
const withSlash = configured.endsWith("/") ? configured : `${configured}/`;
|
||||||
@@ -25,7 +19,7 @@ function resolveRouterBasename() {
|
|||||||
|
|
||||||
const prefix = withSlash.replace(/\/$/, "");
|
const prefix = withSlash.replace(/\/$/, "");
|
||||||
if (pathname === prefix || pathname.startsWith(`${prefix}/`)) {
|
if (pathname === prefix || pathname.startsWith(`${prefix}/`)) {
|
||||||
return withSlash;
|
return prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "/";
|
return "/";
|
||||||
|
|||||||
Reference in New Issue
Block a user