React Router - TypeError:无法读取未定义的属性'toUpperCase'

时间:2015-09-23 09:31:37

标签: reactjs react-router

在使用React时偶然发现了这个问题。我似乎无法找到解决方案。堆栈跟踪没有多大帮助,因为该脚本与webpack捆绑在一起。

这是我从控制台获得的内容

[HMR] Waiting for update signal from WDS...
Warning: React.createElement: type should not be null or undefined. It should be a string (for DOM elements) or a ReactClass (for composite components).
Warning: React.createElement: type should not be null or undefined. It should be a string (for DOM elements) or a ReactClass (for composite components).
Warning: Only functions or strings can be mounted as React components.
Uncaught TypeError: Cannot read property 'toUpperCase' of undefined
[WDS] Hot Module Replacement enabled.

尝试渲染此App组件时遇到

import React from 'react'
import { Router, Route, IndexRoute } from 'react-router'
import { TableRequest, TableEngineer } from './tables.jsx'
import createBrowserHistory from 'history/lib/createBrowserHistory'
export class App extends React.Component {
    render() {
        return (
            <Router history={createBrowserHistory()}>
                <Route path="/" component={Index}>
                    <IndexRoute component={Home} />
                    <Route path="indeks-permohonan" component={TableRequest} />
                    <Route path="indeks-work-order" component={TableEngineer} />
                    <Route path="*" component={NotFound} />
                </Route>
            </Router>
            )
    }
}

包裹清单

├── babel-core@5.8.25
├── babel-loader@5.3.2
├── file-loader@0.8.4
├── history@1.10.1
├── lodash@3.10.1
├── path@0.12.7
├── react@0.13.3
├── react-bootstrap@0.25.2
├── react-hot-loader@1.3.0
├── react-router@1.0.0-rc1
├── react-router-bootstrap@0.19.0
├── reactable@0.11.4
├── webpack@1.12.2
└── webpack-dev-server@1.11.0

3 个答案:

答案 0 :(得分:0)

它只是意味着Stringundefined,而代码在未定义的字符串上调用toUpperCase()。你必须弄清楚你的文件中那段代码的位置。您可以在对此类字符串调用toUpperCase()之前添加未定义的检查。

答案 1 :(得分:0)

尝试将caja --no-desktop 更新为v1.0。使用v0.13时会发生错误。

npm安装该版本,因为还没有稳定的1.0版本。您必须手动将react-router添加到package.json。

答案 2 :(得分:0)

您需要导入IndexHomeNotFound组件。