# All files / src App.tsx

0% Statements 0/8
0% Branches 0/4
0% Functions 0/3
0% Lines 0/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74

     import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
    import './i18n';
    import { AuthProvider } from './context/AuthContext';
    import { ThemeProvider } from './context/ThemeContext';
    import { ToastProvider } from './components/ui/Toast';
    import { Layout } from './components/layout/Layout';
    import { useAuth } from './hooks/useAuth';
    import { HomePage } from './pages/HomePage';
    import { LoginPage } from './pages/LoginPage';
    import { RegisterPage } from './pages/RegisterPage';
    import { ForgotPasswordPage } from './pages/ForgotPasswordPage';
    import { DocumentPage } from './pages/DocumentPage';
    import { HistoryPage } from './pages/HistoryPage';
    import { GlossaryPage } from './pages/GlossaryPage';
    import { CollabPage } from './pages/CollabPage';
    import { CollabWorkspace } from './pages/CollabWorkspace';
    import { UserCenterPage } from './pages/UserCenterPage';
    import { PricingPage } from './pages/PricingPage';
    import { PaymentResultPage } from './pages/PaymentResultPage';
    import { SettingsPage } from './pages/SettingsPage';
    import { AboutPage, HelpPage, PrivacyPage, TermsPage, NotFoundPage } from './pages/StaticPages';

    function ProtectedRoute({ children }: { children: React.ReactNode }) {
      const { isAuthenticated, loading } = useAuth();
      if (loading) return null;
      if (!isAuthenticated) {
        return <Navigate to="/login" state={{ from: window.location.pathname }} replace />;
      }
      return <>{children}</>;
    }

    function AppRoutes() {
      return (
        <Routes>
          <Route path="/" element={<HomePage />} />
          <Route path="/login" element={<LoginPage />} />
          <Route path="/register" element={<RegisterPage />} />
          <Route path="/forgot-password" element={<ForgotPasswordPage />} />
          <Route path="/documents" element={<ProtectedRoute><DocumentPage /></ProtectedRoute>} />
          <Route path="/history" element={<ProtectedRoute><HistoryPage /></ProtectedRoute>} />
          <Route path="/glossary" element={<ProtectedRoute><GlossaryPage /></ProtectedRoute>} />
          <Route path="/collab/workspace" element={<ProtectedRoute><CollabWorkspace /></ProtectedRoute>} />
          <Route path="/collab" element={<ProtectedRoute><CollabPage /></ProtectedRoute>} />
          <Route path="/user/*" element={<ProtectedRoute><UserCenterPage /></ProtectedRoute>} />
          <Route path="/settings" element={<ProtectedRoute><SettingsPage /></ProtectedRoute>} />
          <Route path="/pricing" element={<PricingPage />} />
          <Route path="/subscription/result" element={<PaymentResultPage />} />
          <Route path="/about" element={<AboutPage />} />
          <Route path="/help" element={<HelpPage />} />
          <Route path="/privacy" element={<PrivacyPage />} />
          <Route path="/terms" element={<TermsPage />} />
          <Route path="*" element={<NotFoundPage />} />
        </Routes>
      );
    }

    function App() {
      return (
        <BrowserRouter>
          <AuthProvider>
            <ThemeProvider>
              <ToastProvider>
                <Layout>
                  <AppRoutes />
                </Layout>
              </ToastProvider>
            </ThemeProvider>
          </AuthProvider>
        </BrowserRouter>
      );
    }

    export default App;