2
<Router>
  <Routes>
    <Route path="users" element={<Users />} />
    <Route path="posts" element={<Posts />} />
    <Route path="" element={<Redirect to="/users" />} />
  </Routes>
</Router>

I've just upgraded to React Router v6 and my Redirect isn't working. I'm a beginner and just started learning React, it's a bit hard for me to wrap my head around it, thanks for any help

Chilaxathor
  • 626
  • 1
  • 9
  • 10

1 Answers1

3

With React Router v6 you can't use <Redirect> anymore, you'll need to use <Navigate> and specify the replace prop (if you want to redirect instead of just navigate):

<Router>
  <Routes>
    <Route path="users" element={<Users />} />
    <Route path="posts" element={<Posts />} />
    <Route path="" element={<Navigate to="/users" replace />} />
  </Routes>
</Router>
Stephen Jenkins
  • 1,776
  • 3
  • 24
  • 39