I started to build next website using reactJS and nodejs. The website is required to have minimum 2 languages and it should be possible to share link to website in desired language. I concluded quickly that what i need is to have following url structure
domain.com/en-GB
domain.com/en-GB/gallery
domain.com/en-GB/contact
front end Router:
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
...
<Router>
<React.Fragment>
<Header />
<Suspense fallback={<Loading />}>
<Switch>
<Route exact path="/">
<Landing />
</Route>
<Route path="/gallery">
<Gallery />
</Route>
<Route path="/about-us">
<AboutUs />
</Route>
<Route path="/contact">
<Contact />
</Route>
<Route>
<PageNotFound />
</Route>
</Switch>
</Suspense>
<Footer />
</React.Fragment>
</Router>
...
front end menu:
import { NavLink } from "react-router-dom";
...
<NavLink to="/about-us">
{Lang.resolve("HEADER_MENU_ABOUT_US")}
</NavLink>
...
pieces of webpack config:
...
const extractTextPlugin = new ExtractTextPlugin({
filename: "css/style.[hash:8].css",
allChunks: true
});
module.exports = {
...
output: {
filename: "js/main.[hash:8].js"
}
...
},
...
server routing:
...
const router = express.Router();
let landing = (req, res, next) => {
res.sendFile(path.join(__dirname, "../../index.html")); // html build by webpack
};
router.get("/", landing);
router.get("/:view", landing);
...
I was wondering if there is something already baked into reactJS to allow this or i need to manually append language part of url like: <Route path={_LANG_ + "/gallery"}>.
Probably some adjustments are also needed to the server routing and webpack paths otherwise it will be a problem while loading css, js files domain.com/en-GB/css/style.css.
Maybe someone already fought this idea and could have some tips.