respect lms admin base path in routing

This commit is contained in:
2026-07-08 09:48:35 +09:00
parent 6d64337467
commit e63b1c6f43
2 changed files with 13 additions and 2 deletions
+3 -1
View File
@@ -4,9 +4,11 @@ import { BrowserRouter } from 'react-router-dom';
import App from './App';
import './index.css';
const routerBasename = import.meta.env.BASE_URL.replace(/\/+$/, '') || '/';
createRoot(document.getElementById('root')!).render(
<StrictMode>
<BrowserRouter>
<BrowserRouter basename={routerBasename}>
<App />
</BrowserRouter>
</StrictMode>
+10 -1
View File
@@ -45,13 +45,22 @@ export const navItems: NavItem[] = [
// };
const appRoutes: AppRoute[] = [...navItems.map((item) => item.id), 'profile'];
const publicBasePath = import.meta.env.BASE_URL.replace(/\/+$/, '');
const stripPublicBasePath = (pathname: string): string => {
if (!publicBasePath || publicBasePath === '/') return pathname;
if (pathname === publicBasePath) return '/';
if (pathname.startsWith(`${publicBasePath}/`)) return pathname.slice(publicBasePath.length) || '/';
return pathname;
};
export const isAppRoute = (value: string): value is AppRoute => appRoutes.includes(value as AppRoute);
export const getRoutePath = (route: AppRoute) => routePaths[route];
export const getRouteFromPathname = (pathname: string): AppRoute | null => {
const normalizedPath = pathname === '/' ? routePaths[defaultRoute] : pathname.replace(/\/+$/, '');
const routePathname = stripPublicBasePath(pathname);
const normalizedPath = routePathname === '/' ? routePaths[defaultRoute] : routePathname.replace(/\/+$/, '');
const entry = Object.entries(routePaths).find(([, path]) => path === normalizedPath);
return entry ? (entry[0] as AppRoute) : null;
};