The useNavigate hook is a feature provided by React Router v6 that allows for programmatic navigation between different pages or routes within a React application using function components���.Core FunctionalityThe hook returns a function (navigate) which can be called to change the current route.Developers can use this in event handlers (like after form submission or button clicks) to move users to different pages based on app logic.It replaces the earlier useHistory hook from previous versions of React Router��.Typical Usageimport { useNavigate } from 'react-router-dom';
function MyComponent() {
const navigate = useNavigate();
const goToDashboard = () => {
navigate('/dashboard'); // navigates to /dashboard route
};
return Go to Dashboard;
}
Top comments (0)