Refactor UUID generation, remove unused logger and encryption utilities, and clean up request handling
- Updated `generateUUID` function for improved readability and performance. - Deleted `logger.ts`, `other.ts`, `request.ts`, `storage.ts`, `tansParams.ts`, and `validate.ts` as they were no longer needed. - Simplified TypeScript configuration by removing unnecessary paths and aliases. - Enhanced Vite configuration for better project structure and maintainability.
This commit is contained in:
61
src/router/index.tsx
Normal file
61
src/router/index.tsx
Normal file
@@ -0,0 +1,61 @@
|
||||
import { useEffect } from 'react';
|
||||
import { Navigate, Route, Routes, useLocation, useNavigate } from 'react-router-dom';
|
||||
import MainLayout from '../components/layout/MainLayout';
|
||||
import HomePage from '../pages/Home';
|
||||
import LoginPage from '../pages/Login';
|
||||
import AgentsPage from '../pages/Agents';
|
||||
import SkillsPage from '../pages/Skills';
|
||||
import CronPage from '../pages/Cron';
|
||||
import ScriptsPage from '../pages/Scripts';
|
||||
import SettingPage from '../pages/Setting';
|
||||
import KnowledgePage from '../pages/Knowledge';
|
||||
import { DEFAULT_PATH } from './routes';
|
||||
import { RedirectAuthenticated, RequireAuth, isAuthenticated } from './auth';
|
||||
import { onAuthLogout } from './auth-session';
|
||||
|
||||
function AuthLogoutRedirector() {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
return onAuthLogout(({ from }) => {
|
||||
const currentPath = location.pathname === '/login' ? undefined : location.pathname;
|
||||
navigate('/login', {
|
||||
replace: true,
|
||||
state: { from: from ?? currentPath },
|
||||
});
|
||||
});
|
||||
}, [location.pathname, navigate]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function AppRouter() {
|
||||
const initialPath = isAuthenticated() ? DEFAULT_PATH : '/login';
|
||||
|
||||
return (
|
||||
<>
|
||||
<AuthLogoutRedirector />
|
||||
<Routes>
|
||||
<Route path="/" element={<Navigate to={initialPath} replace />} />
|
||||
<Route element={<RedirectAuthenticated />}>
|
||||
<Route path="/login" element={<LoginPage />} />
|
||||
</Route>
|
||||
|
||||
<Route element={<RequireAuth />}>
|
||||
<Route element={<MainLayout />}>
|
||||
<Route path="/home" element={<HomePage />} />
|
||||
<Route path="/agents" element={<AgentsPage />} />
|
||||
<Route path="/skills" element={<SkillsPage />} />
|
||||
<Route path="/cron" element={<CronPage />} />
|
||||
<Route path="/scripts" element={<ScriptsPage />} />
|
||||
<Route path="/setting" element={<SettingPage />} />
|
||||
<Route path="/knowledge" element={<KnowledgePage />} />
|
||||
</Route>
|
||||
</Route>
|
||||
|
||||
<Route path="*" element={<Navigate to={initialPath} replace />} />
|
||||
</Routes>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user