我创建了这个示例 repo,它使用 rails (v4.2.6) 和 react-rails (v1.6.2) 和 react-router (v2.0.0-rc5):https ://github.com/pioz/rails_with_react_and_react_router_example
在文件中app/views/application/react_entry_point.html.erb
,我MountUp
使用
<%= react_component('MountUp', {}, {prerender: false}) %>
该组件MountUp
呈现我的路由器:
class MountUp extends React.Component {
render() {
return(
<Router history={History}>
<Route path="/" component={App}>
<IndexRoute component={Index} />
<Route path="/contact" component={Contact}/>
<Route path="/about" component={About}/>
</Route>
</Router>
)
}
}
一切正常,但如果我更改选项,prerender: true
我会收到一个奇怪的错误React::ServerRendering::PrerenderError in Application#react_entry_point
:
Encountered error "Error: Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings." when prerendering MountUp with {}
Object.invariant [as default] ((execjs):21983:16)
createHashHistory ((execjs):24108:130)
(execjs):22633:20
wrapDeprecatedHistory ((execjs):25285:61)
createRouterObjects ((execjs):25259:23)
componentWillMount ((execjs):25228:38)
ReactCompositeComponentMixin.mountComponent ((execjs):8138:13)
wrapper [as mountComponent] ((execjs):3131:22)
Object.ReactReconciler.mountComponent ((execjs):6583:36)
ReactCompositeComponentMixin.mountComponent ((execjs):8153:35)
/Users/pioz/.rvm/gems/ruby-2.3.0/gems/execjs-2.6.0/lib/execjs/external_runtime.rb:39:in `exec'
...
如何渲染此应用服务器端?这是正确的方法吗?