In React Router 5 I could use a <redirect path='' /> but that has been removed in React Router 6. I think it's been replaced with <Navigate>, but that throws a security error for this use case.
Redirect is no longer in the react-router version 6. For react-router-dom v6, You can use Navigate instead of Redirect. Here is the example:
import {Routes, Route, Navigate } from "react-router-dom";
function App() {
return (
<>
<Routes>
<Route path="/404" element={<div>Page Not Found/div>} />
<Route path="*" element={<Navigate replace to="/404" />} />
</Routes>
</>
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With