How do protected routes work?
Model answer
Wrap protected pages in a component that checks whether the user is signed in and, if not, redirects with <Navigate to="/login" replace />. Often it is a layout route that renders <Outlet /> when allowed.
Remember that this only hides the UI. The server must still check permissions on every API request.
Learn this topic
React Router: Multiple Pages, Links, Params, Layouts and Protected Routes in the course React.js Full Course: Beginner to Advanced.
Sign in to add your own answer.