Files
platform-project/platform/frontend-user/src/App.tsx
T
Арсентьев Александр 07dbde2a0e Initial monorepo structure
2026-08-06 11:23:37 +03:00

30 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Routes, Route, Navigate } from 'react-router-dom'
import { AuthProvider, useAuth } from './contexts/AuthContext'
import Layout from './components/Layout'
import Login from './pages/Login'
import Register from './pages/Register'
import Dashboard from './pages/Dashboard'
import ModuleView from './pages/ModuleView'
function ProtectedRoute({ children }: { children: React.ReactNode }) {
const { user, loading } = useAuth()
if (loading) return <div className="flex items-center justify-center h-screen">Загрузка...</div>
if (!user) return <Navigate to="/login" />
return <>{children}</>
}
export default function App() {
return (
<AuthProvider>
<Routes>
<Route path="/login" element={<Login />} />
<Route path="/register" element={<Register />} />
<Route path="/" element={<ProtectedRoute><Layout /></ProtectedRoute>}>
<Route index element={<Dashboard />} />
<Route path="module/:slug" element={<ModuleView />} />
</Route>
</Routes>
</AuthProvider>
)
}