Note: Always include Redirect at the end, just before the end tag, otherwise your default routing will not work. This solution is more involved, leveraging custom TypeScript decorators which inject match, history and/or location data into your React.Component class, which gets you full type safety without needing any type guards, as the previous example required. 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. Routing with typed parameters and injected properties. Before proceeding with this guide I would highly recommend going over the official React Router Guide to familiarize yourself with the terminology. It is a well thought out library with an extensive test suite and support for browser, react-native, and server-side rendering. Next, include the component and pass the default route /home to the to attribute. React Router is one of the most popular routing libraries in the React ecosystem. To set the default Route, you have to use component from the react-router-dom library. 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. |