Answer the question
In order to leave comments, you need to log in
How to correctly load data in server rendering + react router v4?
Pilu isomorphic/universal application. I do not quite understand how to work with the data.
In my server.js, in order for the props to be filled with data before rendering, I implemented this:
routes.some(route => {
const match = matchPath(req.url, route);
if (match && typeof route.loadData === "function"){
promises.push(store.dispatch(route.loadData()));
}
return match
});
Promise.all(promises).then(() => {
// после того как получил все данные - делаю рендер
}
Answer the question
In order to leave comments, you need to log in
You need to save the information that the data has been loaded in any convenient way. This can be done both at the bootloader level
// что-то вроде этого
promises.push(
store
.dispatch(route.loadData())
.then(() => store.dispatch(dataForRouteLoaded(req.url))
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question