React 项目开发:从服务器渲染到游戏引擎搭建
1. 服务器渲染与数据预取
在项目接近完成时,需要为 Express 服务器添加数据获取功能。以下是具体操作步骤:
1. 导入必要模块 :打开 server-production.es6 文件,在文件顶部添加以下导入代码:
import { Provider } from 'react-redux'
import configureStore from './build/shared/store/configure-store'
import { fetchPostsAsync } from './build/shared/api/fetch-posts'
- 替换路由代码 :将
const approutes替换为以下代码:
const appRoutes = (app) => {
app.get('*', (req, res) => {
match({ routes, location: req.url },
(err, redirectLocation, props) => {
if (err) {
res.status(500).send(err.message);
}
超级会员免费看
订阅专栏 解锁全文
95

被折叠的 条评论
为什么被折叠?



