Interview question
How do you handle redirects and navigate? Redirects और navigate कैसे handle करें?
Answer
import { useNavigate } from 'react-router-dom';
function LoginForm() {
const navigate = useNavigate();
const handleLogin = async () => {
// login logic
navigate('/dashboard');
};
}
// Redirect old routes
<Route path='/old' element={<Navigate to='/new' />} />useNavigate से programmatically navigate कर सकते हैं।Was this answer clear?