platform/lms-adm-fe release promotion snapshot
This commit is contained in:
+3
-1
@@ -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
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user