How can you use the useHistory hook in React Router v5 to navigate programmatically within a functional component

0 votes
With the help of code can i know How can you use the useHistory hook in React Router v5 to navigate programmatically within a functional component?
23 hours ago in Node-js by Ashutosh
• 27,610 points
13 views

1 answer to this question.

0 votes

In React Router v5, the useHistory hook is used to navigate programmatically within a functional component.

Usage:

import { useHistory } from 'react-router-dom';

function MyComponent() {

  const history = useHistory();

  const handleClick = () => {

    history.push('/about'); // Navigate to /about

  };

  return <button onClick={handleClick}>Go to About</button>;

}

answered 21 hours ago by anonymous

Related Questions In Node-js

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How can you implement a private route that requires authentication before rendering a component in React Router?

Basic Private Route Implementation (v6) import { Navigate, ...READ MORE

answered 4 days ago in Node-js by anonymous
39 views
0 votes
0 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How can you programmatically navigate to a different route in React Router v5?

In React Router v5, you can programmatically ...READ MORE

answered 4 days ago in Node-js by anonymous
28 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP