react-router Uncaught TypeError:无法读取未定义的属性“toUpperCase" [英] react-router Uncaught TypeError: Cannot read property 'toUpperCase' of undefined

查看:52
本文介绍了react-router Uncaught TypeError:无法读取未定义的属性“toUpperCase"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 react-router,但是当我编写一个简单的路由时不起作用,并且控制台显示 Uncaught TypeError: Cannot read property 'toUpperCase' of undefined.

I am trying to use the react-router but when I write a simple route doesn't work and the console show Uncaught TypeError: Cannot read property 'toUpperCase' of undefined.

否则当我在没有运行良好的反应路由器的情况下使用时

Otherwise when I use without the react-router that work well

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

var App = React.createClass({
    render: function () {
        return (
            <div>Hello World</div>
        );
    }
});


React.render((
  <Router>
    <Route path="/" component={App} />
  </Router>
), document.body);

错误来自反应库的这一行

The error is from this line of the react library

function autoGenerateWrapperClass(type) {
  return ReactClass.createClass({
    tagName: type.toUpperCase(), //<----
    render: function() {
      return new ReactElement(
        type,
        null,
        null,
        null,
        null,
        this.props
      );
    }
  });
}

推荐答案

您正在使用 1.0 Beta 文档中的示例,但您可能正在运行最新的稳定版本 (0.13).master 中的文档来自 1.0 Beta,这是混淆的根源.

You are using examples from 1.0 Beta docs, but you are likely running the latest stable version (0.13). The docs in master are from 1.0 Beta, that's the source of confusion.

阅读最新稳定版本的文档:https://github.com/ReactTraining/react-router/tree/master/docs

Read the docs for the latest stable version: https://github.com/ReactTraining/react-router/tree/master/docs

这篇关于react-router Uncaught TypeError:无法读取未定义的属性“toUpperCase"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆