0
我试图更新我的Web应用程序实现从React路由器0.13.x到1.0.0,这是使用Fluxxor和服务器端渲染在后端。React路由器服务器端与Fluxxor渲染
我没有找到什么好的迁移指南,把这段代码转换:
something.serve(function (req, res) {
Router.run(routes, req.path, function (Root, state) {
fetchData(state.routes).then(function (data) {
var flux = new Flux(null, user, data, state.params, currencies, categories, sortTypes),
serializedFlux = flux.serialize(),
content = React.renderToString(
React.createElement(Handler, {
flux: flux,
params: state.params
})
);
});
});
});
到新版本。反应路由器中的下面的例子并不清楚,因为它没有解释我们如何访问state.params或state.routes(或类似的东西),这些都是初始化flux存储所必需的。
阵营路由器server rendering例如:现在
import { renderToString } from 'react-dom/server'
import { match, RoutingContext } from 'react-router'
import routes from './routes'
serve((req, res) => {
// Note that req.url here should be the full URL path from
// the original request, including the query string.
match({ routes, location: req.url }, (error, redirectLocation, renderProps) => {
if (error) {
res.status(500).send(error.message)
} else if (redirectLocation) {
res.redirect(302, redirectLocation.pathname + redirectLocation.search)
} else if (renderProps) {
res.status(200).send(renderToString(<RoutingContext {...renderProps} />))
} else {
res.status(404).send('Not found')
}
})
})
感谢过去了,你的回答实际上帮助我解决了这个问题。但只是为了记录相当于state.routes是renderProps.routes而不renderProps.components。 – p0o
是的,哎呀。我现在修复了这个问题。谢谢! –