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

0 votes
With the help of code can i know How can you programmatically navigate to a different route in React Router v5?
Apr 17, 2025 in Node-js by Nidhi
• 16,260 points
555 views

1 answer to this question.

0 votes

In React Router v5, you can programmatically navigate to a different route using the useHistory hook:

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

const MyComponent = () => {

  const history = useHistory();


  const navigate = () => {

    history.push('/new-route');

  };


  return <button onClick={navigate}>Go</button>;

};

answered Apr 17, 2025 by anonymous

Related Questions In Node-js

0 votes
1 answer

How do you redirect a user to a different route in React Router?

Redirecting a User in React Router 1. Using ...READ MORE

answered Feb 23, 2025 in Node-js by Kavya
490 views
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 Apr 17, 2025 in Node-js by anonymous
570 views
0 votes
1 answer
0 votes
1 answer

How do you pass and use URL parameters in a React-Router route?

Passing and Using URL Parameters in React ...READ MORE

answered Feb 23, 2025 in Node-js by Kavya
516 views
0 votes
1 answer

How do you model a many-to-many relationship in MongoDB with an example?

In MongoDB, a many-to-many relationship can be ...READ MORE

answered Feb 23, 2025 in Node-js by Kavya
554 views
0 votes
1 answer

What is the difference between RDBMS relationships and MongoDB’s data model?

Feature RDBMS (SQL Databases) MongoDB (NoSQL Document Database) Data Structure Tables ...READ MORE

answered Feb 23, 2025 in Node-js by Kavya
477 views
0 votes
1 answer
0 votes
1 answer

Write a query for a compound index to optimize a search operation in MongoDB.

A compound index improves search performance by ...READ MORE

answered Feb 23, 2025 in Node-js by Kavya
535 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