I am trying to implement a PrivateRoute logic with the newly released Router but it seems it doesn't work as expected..
import { Route, Routes, Navigate } from "react-router-dom";
import LogInPage from "./pages/LogIn";
import DashboardPage from "./pages/Dashboard";
function PrivateRoute({ path, element }) {
const auth = true;
return (
<Route
path={path}
element={auth === true ? element : <Navigate replace to="/login" />}
/>
);
}
function App() {
return (
<Routes>
<Route path="/*" element={<PageNotFound />} />
<Route path="/" element={<Navigate replace to="/dashboard" />} />
<Route path="/login" element={<LogInPage />} />
<PrivateRoute
path="/dashboard"
element={<DashboardPage />}
/>
</Routes>
);
}
export default App;
What am I missing? Isn't the PrivateRoute component still a Route
component if it is returning a Route
?