In react router 5 I could use a but that has been removed from react router 6. I think it’s been replaced with , but that throws a security error for this usecase… For whatever reason.
Advertisement
Answer
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:
JavaScript
x
13
13
1
import {Routes, Route, Navigate } from "react-router-dom";
2
3
function App() {
4
return (
5
<>
6
<Routes>
7
<Route path="/404" element={<div>Page Not Found/div>} />
8
<Route path="*" element={<Navigate replace to="/404" />} />
9
</Routes>
10
</>
11
);
12
}
13