Avatar ·

How to programmatically navigate to another page in React Router v6?

Hello everyone! I just started learning React and ran into a problem. I'm using React Router v6 for navigation in my app. Regular links work perfectly, but I need to programmatically redirect the user after certain actions - for example, after successful login or form submission. Here's my login component code: ```javascript import { useNavigate } from 'react-router-dom'; function LoginForm() { const handleSubmit = async (event) => { event.preventDefault(); const response = await fetch('/api/login', { method: 'POST', body: new FormData(event.target) }); if (response.ok) { // Here I want to navigate to /dashboard console.log('Successful login! Need to navigate to dashboard'); } }; ```