Problem Statement
How to protect private routes in React?
Explanation
Create a wrapper route that checks if the user is authenticated. If not, redirect them to login. This ensures only logged-in users can access certain pages.
Code Solution
SolutionRead Only
const PrivateRoute = ({ children }) => isAuth ? children : <Navigate to='/login' />;Practice Sets
This question appears in the following practice sets: