路由器createElement和渲染失败

我正在探索react-router并遇到一个非常基本的问题。 令人沮丧的部分是我在另一个应用程序中使用react-router,它工作正常!

我在控制台中得到这个错误。 我在这里错过了什么?

警告:React.createElement:type不应该为null,undefined,boolean或number。 它应该是一个字符串(用于DOM元素)或ReactClass(用于复合组件)。

未捕获的不变违规:元素类型无效:期望一个字符串(对于内置组件)或类/函数(对于复合组件),但得到:object。

var React = require('react');
var ReactDOM = require('react-dom');
var Router = require('react-router');
var Route = require('react-router').Route;
var hashHistory = require('react-router').hashHistory;

var App = React.createClass({
  render: function() {
    return <div>App Rendered from React Router!</div>
  }
});

//this works - there is nothing wrong with App component
// ReactDOM.render((
//   <App/>
// ), document.getElementById('app'));


//This works - just so I understand the basics
// var Child = React.createElement('div',{className:'child'});
// var Parent = React.createElement('div',{className:'parent'},Child);
// ReactDOM.render(Parent, document.getElementById('app'));


//this doesn't work - copy pasted from tutorial
ReactDOM.render((
  <Router history={hashHistory}>
    <Route path="/" component={App}/>
  </Router>
), document.getElementById('app'));

//Babel transpiled code
// ReactDOM.render(React.createElement(
//    Router,
//    { history: hashHistory },
//    React.createElement(Route, { path: '/', component: App })
//  ), document.getElementById('app'));


//this doesn't work
// var route = React.createElement(Route, { path: '/', component: App });
// var router = React.createElement(Router,{ history: hashHistory });
//
// ReactDOM.render(router, document.getElementById('app'));

你需要导入Router

var Router = require('react-router').Router
链接地址: http://www.djcxy.com/p/52175.html

上一篇: router createElement and render fail

下一篇: iscroll generates warning and error since upgrading to react 0.14.3