Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 4 of 5 · React Router and Navigation
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?