87ec792fd5
Добавил авторизацию в приложение, сделал регистарцию, добавил мидлы
50 lines
1.1 KiB
React
50 lines
1.1 KiB
React
import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";
|
|
import Dashboard from "./pages/Dashboard";
|
|
import PartDetail from "./pages/PartDetail";
|
|
import AddPartPage from "./pages/AddPartPage";
|
|
import AuthForm from "./components/AuthForm";
|
|
|
|
const PrivateRoute = ({ children }) => {
|
|
const token = localStorage.getItem("token");
|
|
|
|
if (!token) {
|
|
return <Navigate to="/login" replace />;
|
|
}
|
|
|
|
return children;
|
|
};
|
|
|
|
export default function App() {
|
|
return (
|
|
<BrowserRouter>
|
|
<Routes>
|
|
<Route path="/login" element={<AuthForm />} />
|
|
<Route
|
|
path="/"
|
|
element={
|
|
<PrivateRoute>
|
|
<Dashboard />
|
|
</PrivateRoute>
|
|
}
|
|
/>
|
|
<Route
|
|
path="/part/:id"
|
|
element={
|
|
<PrivateRoute>
|
|
<PartDetail />
|
|
</PrivateRoute>
|
|
}
|
|
/>
|
|
<Route
|
|
path="/add"
|
|
element={
|
|
<PrivateRoute>
|
|
<AddPartPage />
|
|
</PrivateRoute>
|
|
}
|
|
/>
|
|
</Routes>
|
|
</BrowserRouter>
|
|
);
|
|
}
|