I am trying to keep the language always in the route of my app like this: http://localhost:5173/en/ so if I go to this address http://localhost:5173, it should directly redirect to http://localhost:5173/en/ or http://localhost:5173/fr/ depending on the language on the context variable.
I am using React js v:18.2.0, React-router-dom v:6.4.1 and Vite v:3.1.0
Routepage:
import {
Routes,
Route,
} from "react-router-dom";
import Auth from "../pages/Auth.jsx";
const AppRoutes = () => {
return (
<Routes baseName="/">
<Route path=":lang/">
<Route path="authentification" element={<Auth/>} />
</Route>
</Routes>
);
}
export default AppRoutes;
app.js:
import AppRoutes from "./routes";
import Footer from "./components/footer/Footer.jsx";
import {useContext} from "react";
import {AppContext} from "./context/AppContext.jsx";
import "./assets/styles/app.css";
function App() {
const {lang, setLang} = useContext(AppContext)
return (
<div className="App">
<AppRoutes />
<Footer lang={lang} setLang={setLang}/>
</div>
)
}
export default App