【问题标题】:React - Uncaught TypeError: Cannot read property 'func' of undefinedReact - 未捕获的类型错误:无法读取未定义的属性“func”
【发布时间】:2018-04-21 09:41:56
【问题描述】:

我收到错误消息:

未捕获的类型错误:无法读取未定义的属性 'func'

但我不知道为什么,我已经用谷歌搜索了这个错误,并找到了同样错误的每个帖子,但没有运气。谁能帮帮我?

我正在使用 react-router@3.0.2

index.jsx

import React from 'react';
import ReactDOM from 'react-dom';
import { Router, browserHistory } from 'react-router';
import { Helmet } from 'react-helmet';

import Routes from './config/routes';

ReactDOM.render(
    <div>
        <Helmet>
            <meta charSet='utf-8'/>
            <title>Skelton</title>
            <link rel='icon' href='images/favicon.png'/>
            <link rel='stylesheet' href='style.css'/>
        </Helmet>
        <Router routes={Routes()} history={browserHistory}/>
    </div>
, document.getElementById('root'));

route.js

import React from 'react';
import { Route, IndexRoute } from 'react-router';

import Example1 from '../pages/Example1';

export function routes() {
    return (
        <Route>
            <Route path='/' component={Example1}/>
            <IndexRoute component={Example1}/>
        </Route>
    );
}

export default routes;

Example1.js

import React, { Component } from 'react';
import PropTypes from 'prop-types';

class Example1 extends Component {
    render() {
        return (
            <div>
                <h1>Hello World! This is Example 1.</h1>
            </div>
        );
    }
}

export default Example1;

最初我没有导入 PropTypes,因为我还不需要它。

【问题讨论】:

  • 所以,你没有使用 prop -types,但你得到了那个错误,对吧?
  • 我认为您正在显示与错误相关的任何代码。你能从控制台找到错误的位置并添加相应的代码 sn-ps 吗?或来自控制台的详细错误.. ?
  • @Panther 错误与代码有关,因为最初我在 index.jsx 中执行

    Hello World!

    并且一切正常。当我开始添加路线时,问题就出现了。
  • @Héctor 我在导入和不使用 PropTypes 作为导入时都会遇到错误。

标签: javascript reactjs react-router jsx


【解决方案1】:

它看起来像一个 react-router 错误(与 prop 类型有关。)它正在 react-router 3.2.0 上运行

在此处检查问题: https://github.com/ReactTraining/react-router/issues/5605

【讨论】:

    【解决方案2】:

    很容易解决。

    发生这种情况是因为您使用的是 react-router 2.0.0 版

    只要输入“npm install --save react-router@3.2.0”

    它现在应该可以正常工作了。

    【讨论】:

      猜你喜欢
      • 2017-07-06
      • 1970-01-01
      • 1970-01-01
      • 2015-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多