让react-router与Rails 5& gem' react-rails',#0.1; 1.10.0'

时间:2017-02-26 05:52:30

标签: javascript ruby reactjs react-router ruby-on-rails-5

我有一个Rails 5应用程序,反应安装了gem 'react-rails', '1.10.0'

我也想使用react-router所以我手动让react-router JS加载,因为它们没有可用的gem。我可以在控制台a中提交ReactRouter以确认ReactRouter次加载。

我试图让反应路由器工作但它错了。这是我的基本设置:

welcome.html.erb

<div id="root"></div>
<%= react_component 'RouterTest' %>

_router_test.jsx

var Route = ReactRouter.Route;
var Router = ReactRouter;
var browserHistory = ReactRouter.browserHistory;

var RouterTest = React.createClass({
  render() {
    return ( <div> <h1>RouterTest!</h1> </div> )
  }
});

var routes = (
    <Router history={browserHistory}>
        <Route path="/" component={RouterTest}/>
    </Router>
);

ReactDOM.render(routes , document.getElementById('root'));

这是控制台中的错误:

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).
printWarning @ react.self-fd40d62….js?body=1:1275
warning @ react.self-fd40d62….js?body=1:1299
createElement @ react.self-fd40d62….js?body=1:3085
(anonymous) @ _router_test.self-b3b194f….js?body=1:23
react.self-fd40d62….js?body=1:841 Uncaught Error: _registerComponent(...): Target container is not a DOM element.
    at invariant (react.self-fd40d62….js?body=1:841)
    at Object._renderNewRootComponent (react.self-fd40d62….js?body=1:20670)
    at Object._renderSubtreeIntoContainer (react.self-fd40d62….js?body=1:20760)
    at Object.render (react.self-fd40d62….js?body=1:20781)
    at _router_test.self-b3b194f….js?body=1:29

有关我在使React Router工作时出错的建议吗?谢谢

0 个答案:

没有答案