我有一个React应用程序,这是我的服务器代码:
app.get('*', (req, res) => {
let history = createMemoryHistory();
let store = configureStore();
let routes = createRoutes(history);
match({ routes, location: req.url }, (error, redirectLocation, renderProps) => {
if (redirectLocation) {
res.redirect(301, redirectLocation.pathname + redirectLocation.search);
} else if (error) {
res.status(500).send(error.message);
} else if (renderProps == null) {
res.status(404).send('Not found');
} else {
let { query, params } = renderProps;
let comp = renderProps.components[renderProps.components.length - 1];
console.log('fetching');
comp.fetchData({ store, params })
.then(() => {
console.log('done fetching');
let html = ReactDOMServer.renderToString(
{ }
);
const template = store.getState().template;
const og = templateToOpenGraph(template);
const full = wrap(html, store.getState(), og);
res.set({ 'Cache-Control': 'public, max-age=300' })
res.send(full);
})
}
});
})
当我启动服务器时,启动就好了.但是当我遇到一条路线(任何路线)时,我收到一个错误:
TypeError: comp.fetchData is not a function
我需要做什么?我不是最好的反应,所以如果我遗漏了一些明显的东西,请告诉我.
谢谢!