Problem Statement
How to perform automatic redirect after login in React?
Explanation
In React Router v6, you can redirect users using the Navigate component after successful login. Once authentication succeeds, set a state like isLoggedIn to true and conditionally render <Navigate to='/dashboard' /> to send the user to the dashboard automatically.
Code Solution
SolutionRead Only
if (isLoggedIn) return <Navigate to='/dashboard' />; else return <LoginForm />;
Practice Sets
This question appears in the following practice sets:
