3

I would like to redirect my url for e.g to '/questions/1' when I only write /questions

1 Answers1

8

You can render a redirect from one path to the other.

If using react-router-dom v5 use the Redirect component:

<Redirect from="/questions" to="/questions/1" />

If using react-router-dom v6 use the Navigate component:

<Route path="/questions" element={<Navigate to="/questions/1" replace />} />
Drew Reese
  • 165,259
  • 14
  • 153
  • 181