Answer the question
In order to leave comments, you need to log in
How to link Express Router with React Router?
The task is to make ssr using Express and React.
It is necessary that along the domain.com/api route - work out the api created using the Express Router.
On the route domain.com/client - issued a React application with react-router-dom or react-router.
app.use('/api', mainRouter)
<Route path='/' component={Home} />
<Route path='/inc' component={Inc} />
<Route path='/input' component={Input} />
How to link these two routes in Express?
Answer the question
In order to leave comments, you need to log in
https://stackoverflow.com/a/52336630/6912339
The bottom line is that we first connect the api router, then issue static resources (css and other), and then redirect all other requests to index.html so that react-router will work. The request coming to the back is checked exactly in the order in which we registered the handlers, that is, first it is checked if it is not for api, then it is not for static resources, and in the end, if none of the above is requested, then it is considered that this is a route frontend and a react application is issued, where the route is processed using react-router.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question