React-router Uncaught TypeError:type.toUpperCase不是函数

时间:2015-09-27 19:37:46

标签: javascript reactjs gulp browserify react-router

我使用最新版本的react,react-router,gulp和browserify 我在beowser控制台得到了这个: 未捕获的TypeError:type.toUpperCase不是函数

app.js中的代码:

"use strict";
var React = require('react');
var Router = require('react-router');
var Header = require('./components/Header');
var Index = require('./components/Index');
var About = require('./components/About')
var Route = Router.Route;
var IndexRoute  = Router.IndexRoute ;


var App = React.createClass({
  render: function(){
    return (
      <div>
        <Header />
        <div>
          {this.props.children}
        </div>
      </div>
    );
  }
})
React.render(<Router><Route path="/" component={App}>
<IndexRoute  component={Index}/>
<Route path="about" component={About}/>
</Route>
</Router>, document.getElementById('app'));

1 个答案:

答案 0 :(得分:0)

只需将您的反应路由器版本从0.0.13升级到1.0.0-rc1(测试版),以下代码仅适用于change log中提到的1.0.0测试版。

React.render(<Router><Route path="/" component={App}>
<IndexRoute  component={Index}/>
<Route path="about" component={About}/>
</Route>
</Router>, document.getElementById('app'));

升级版本后,您必须正确声明路由器,如下所示。

var React = require('react');
var ReactRouter = require('react-router');
var Router = ReactRouter .Router;
var Route = ReactRouter .Route;

现在路由器已正确定义。这对我有用......尝试一下。