Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 5 of 5 · React Router and Navigation
Interview question

How do you create protected routes? Protected routes कैसे बनाएं?

Answer
function ProtectedRoute({ isAuthenticated, children }) {
  return isAuthenticated ? children : <Navigate to='/login' />;
}

// Usage
<Route
  path='/dashboard'
  element={
    <ProtectedRoute isAuthenticated={isLoggedIn}>
      <Dashboard />
    </ProtectedRoute>
  }
/>
Protected routes authentication check करते हैं।

Was this answer clear?