Note: Always include Redirect at the end, just before the end tag, otherwise your default routing will not work. Your default route is setup, now everytime a user hits an incorrect URL on the browser, the user will get redirected to the Home page of your application. React Router with Switch and Link - Code. Next, include the component and pass the default route /home to the to attribute. Details: How to install latest version of React Router Dom npm install react-routeremail protected or yarn. To set the default Route, you have to use component from the react-router-dom library. I was recently asked about the use of a Switch component in my React project that used client-side routing via React Router. In this tutorial, you will learn to set a default Route in React Router so that all the incorrect routes get redirected to the default route Set a default route
0 Comments
Leave a Reply. |