React Router has a component called Redirect that we can use to redirect to pages. We use this component in a couple of cases to improve our shop in the following sections.
Implementing page redirects
Simple redirect
If we visit the / route path, we'll notice that we get the Sorry, this page cannot be found message. Let's change this to redirect to "/products" when the path is /.
- First, we need to import the Redirect component from React Router into Routes.tsx:
import { BrowserRouter as Router, Redirect, Route, Switch } from "react-router-dom";
- We can now use the Redirect component to redirect to "/products" when the path is /:
<Switch>
<Redirect exact={true} from="...