155k views
5 votes
How to redirect in react-router-dom?

User Simoncpu
by
6.8k points

1 Answer

0 votes

Final answer:

In React Router DOM, you can use the Redirect component to redirect to a different route.

Step-by-step explanation:

In React Router DOM, you can redirect to a different route using the Redirect component provided by the library. To use it, you will need to import it from react-router-dom, and then use it in your component's render method. For example:

<Redirect to='./new-route' />

This code will redirect the user to the new-route path specified in the to prop. You can also use this component with conditional rendering, allowing you to redirect dynamically based on certain conditions.

User Hongseok Yoon
by
7.2k points