2016-12-03 38 views
0

我試圖重現this教程問題(它已經過時了一下),並在這個地方與React.createElement

var html = ReactDOM.renderToString(React.createElement(Router.RouterContext, renderProps));

我得到這個錯誤:

Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components).

引發的錯誤
import createBrowserHistory from 'history/createBrowserHistory'; 
let history = createBrowserHistory(); 

ReactDOM.render(
    <Router history={history}> 
     {routes} 
    </Router>, 
    document.getElementById('app') 
); 

我是React的新手,所以也許你可以幫我嗎?

回答

0

正確的章節後,有更新:

October 19, 2015 Update: Previous React.renderToString now lives 
in the react-dom/server package. Additionally, server-side rendering 
with React Router has changed quite a bit. See Server Rendering 
Guide for more details. 

它看起來像你需要根據自己的服務器渲染指南來進行設置。

+0

是的,我檢查了它。不幸的是,該指南並不適合我。我需要爲'React.createElement()'找到解決方案' –

+0

在這種情況下,我會尋找一個更新的教程,並不像那個那麼複雜 –

相關問題