【发布时间】:2018-03-11 17:28:51
【问题描述】:
我正在使用服务器端渲染设置 react-redux 应用程序,而对于 UI,我正在使用 react material-ui。我在应用程序的初始渲染时面临以下警告
以下是项目文件
服务器文件index.js
'use strict';
import express from 'express';
import webpack from 'webpack';
import path from 'path';
import config from '../webpack.config.js';
import chalk from 'chalk';
import bodyParser from 'body-parser';
import handleRender from '../client/src/utils/handleRender.js';
// Tell any CSS tooling (such as Material UI) to use all vendor prefixes if the
// user agent is not known.
global.navigator = global.navigator || {};
global.navigator.userAgent = global.navigator.userAgent || 'all';
const port = 3000;
const app = express();
webpack(config).run((err, results) => {
// console.log(err);
// console.log(results);
});
// Middlewares
app.use(express.static(path.resolve(__dirname, '../build'), { maxAge: 30 * 60 * 60 * 24 * 1000 }));
app.use(bodyParser.json());
app.use(handleRender);
// Trigger server
app.listen(port, function(err) {
if (err) {
console.log(chalk.red("Whoa!!! Server crashed..."), err);
} else {
console.log(chalk.green("YAY!!! Server is up and running..."));
}
});
客户端index.js
'use strict';
import React from 'react';
import { BrowserRouter } from 'react-router-dom';
import { hydrate } from 'react-dom';
import { Provider } from 'react-redux';
import { renderRoutes } from 'react-router-config';
import configureStore from './store';
import App from './containers/App.js';
import routes from './routes/index.js';
hydrate(
<Provider store={configureStore()}>
<BrowserRouter>
{renderRoutes(routes)}
</BrowserRouter>
</Provider>,
document.getElementById('root')
);
如果您需要任何其他信息,请告诉我。提前谢谢!!!
【问题讨论】:
-
我在 Next.js 中遇到了同样的问题。见*.com/a/58626730/2728710
标签: javascript node.js reactjs redux material-ui