I am new at react.js and I am trying to redirect the to /movies if the url is /.
I found some ways but they were either beyond my current understanding or not react-ish.
App.tsx
import { BrowserRouter, Routes, Route } from "react-router-dom";
import Layout from "./components/layouts/Backend";
import Movies from "./pages/movies/Index";
...
export default () => (
<BrowserRouter>
<Routes>
<Route path="/" element={<Layout />}>
<Route path="movies" element={<Movies />} />
...
</Route>
</Routes>
</BrowserRouter>
);
Currently, an empty layout is loaded whenever I enter http://localhost:5173. Therefore, I have to manually click the Movies link to redirect.
I want this to redirect to http://localhost:5173/movies automatically.
>Solution :
Adding an index route with Navigate component should do the trick
<Route
index
element={ <Navigate to="/movies" /> }
/>