router createElement and render fail

I am exploring react-router and ran into a very basic issue. The frustrating part is I am using react-router in another app and it works fine!!.

I get this error in console. What am I missing here?

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).

Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: 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/52176.html

上一篇: 错误呈现反应

下一篇: 路由器createElement和渲染失败