React-router Uncaught TypeError: type.toUpperCase is not a function

99封情书 提交于 2020-01-07 06:55:17

问题


I'm using the latest version of react, react-router, gulp and browserify I got this in beowser console: Uncaught TypeError: type.toUpperCase is not a function

my code in 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:


Just upgrade your react router version from 0.0.13 to 1.0.0-rc1(beta) coz the below code will only work for 1.0.0 beta version which is mentioned in change log.

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

After upgrading version you have to declare router properly like below.

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

Now router is defined properly. This worked for me..give a try.



来源:https://stackoverflow.com/questions/32812055/react-router-uncaught-typeerror-type-touppercase-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!