score:1

app.get('*', (req, res) => {
  // store instance for every incoming request
  const store = createStore(req);

  

  // loadData from api... before rendering
  const promises = matchRoutes(Routes, req.path)
    .map((comp) => {
      console.log(comp, comp.route.component.loadData)
      if (comp.route.component.preload){
        console.log("LoadableComponent")
        comp.route.component.preload().then(res => {
          return res.default.loadData ? res.default.loadData(store) : null;
        })
      }
      return comp.route.component.loadData ? comp.route.component.loadData(store) : null;
    })
    .map(promise => {
      if (promise) {
        return new Promise((resolve, reject) => {
          promise.then(resolve).catch(resolve);
        });
      }
    });


  Promise.all(promises).then(() => {
    console.log(store.getState())
    const context = {};
    const content = renderer(req, store, context);

    if (context.url) {
      return res.redirect(301, context.url);
    }
    if (context.notFound) {
      res.status(404);
    }
    

    Loadable.preloadAll().then(() => {
      res.send(content);
    });
  });
});

Related Query

More Query from same tag