React - Uncaught TypeError:无法读取未定义的属性'func'

Edw*_*ard 5 javascript jsx reactjs react-router

我收到错误:

未捕获的TypeError:无法读取未定义的属性'func'

然而我不知道为什么,我已经用Google搜索了错误,并以相同的错误发送给所有人发帖但没有运气.谁能帮我吗?

我正在使用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'));
Run Code Online (Sandbox Code Playgroud)

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;
Run Code Online (Sandbox Code Playgroud)

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;
Run Code Online (Sandbox Code Playgroud)

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

Héc*_*tor 11

它看起来像一个反应路由器错误(与道具类型有关.)它正在反应路由器3.2.0上工作

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


Nik*_*dav 5

这很容易解决。

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

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

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