Protected Routes and Route Guards
Learn how to restrict access to certain routes based on authentication or authorization state.
Protected routes (or route guards) prevent unauthenticated or unauthorized users from viewing certain parts of an app, redirecting them elsewhere (typically a login page) instead. In React Router, this is commonly implemented as a wrapper component that checks authentication state and either renders its children/<Outlet /> or a <Navigate> redirect, rather than as a built-in router feature.
A protected route is like a security checkpoint before a restricted floor in a building — everyone attempting to reach that floor passes through the checkpoint (the guard component) first, and only those with valid credentials (authenticated state) are allowed through to continue to their original destination, while everyone else is redirected to the front desk (login page).