import { Suspense, lazy, useEffect, type ReactNode } from 'react'; import { Navigate, Route, Routes, useLocation, useNavigate } from 'react-router-dom'; import MainLayout from '../components/layout/MainLayout'; import { useI18n } from '../i18n'; import LoginPage from '../pages/Login'; import { RedirectAuthenticated, RequireAuth, isAuthenticated } from './auth'; import { onAuthLogout } from './auth-session'; import { DEFAULT_PATH } from './routes'; const HomePage = lazy(() => import('../pages/Home')); const ChannelsPage = lazy(() => import('../pages/Channels')); const SkillsPage = lazy(() => import('../pages/Skills')); const CronPage = lazy(() => import('../pages/Cron')); const ScriptsPage = lazy(() => import('../pages/Scripts')); const SettingPage = lazy(() => import('../pages/Setting')); const KnowledgePage = lazy(() => import('../pages/Knowledge')); function RouteLoadingFallback() { const { t } = useI18n(); return (
{t('dashboard.route.loading')}
); } function renderLazyPage(element: ReactNode) { return ( }> {element} ); } function renderSettingViewRedirect(view: 'agents' | 'models') { return ; } 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 ( <> } /> }> } /> }> }> )} /> )} /> )} /> )} /> )} /> )} /> )} /> } /> ); }