我收到了这个警告:
Material-UI: userAgent should be supplied in the muiTheme
context for server-side rendering
使用以下服务器端呈现设置,我做错了什么:
match({routes: R(), location}, (error, redirectLocation, renderProps) => {
if (error) {
console.error("error: "+ error)
} else if (redirectLocation) {
console.error("redirect to " + redirectLocation)
} else if (renderProps) {
const theme = getMuiTheme({userAgent: "all"})
page = ReactDOMServer.renderToStaticMarkup(
<MuiThemeProvider muiTheme={theme}>
<Provider store={store}>
<RouterContext {...renderProps} />
</Provider>
</MuiThemeProvider>
)
} else {
console.error("location nof found: '"+ location +"'")
}
})
答案 0 :(得分:2)
在这个Razzle Material UI Styled Example项目中,我这样设置:
renderToString(<Application userAgent={request.headers['user-agent']} />)
render(<Application userAgent={navigator.userAgent} />, document.getElementById('root'))
class Main extends Component {
constructor(properties, context) {
super(properties, context)
this.muiTheme = getMuiTheme({
userAgent: properties.userAgent
})
}
render() {
return (
<MuiThemeProvider muiTheme={this.muiTheme}></MuiThemeProvider>
)
}
}
效果很好,我认为也是正确的。