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?