React - Uncaught TypeError: Cannot read property 'func' of undefined

坚强是说给别人听的谎言 提交于 2019-12-19 21:19:23

问题


I'm receiving the error:

Uncaught TypeError: Cannot read property 'func' of undefined

Yet I have no idea why, I've Googled the error and gone to everyone post with the same error yet no luck. Can anyone help me out?

I'm using 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;

Originally I didn't import PropTypes because I don't need it, yet.


回答1:


It looks like a react-router bug (related to prop types.) It's working on react-router 3.2.0

Check the issue here: https://github.com/ReactTraining/react-router/issues/5605




回答2:


It's very easy to resolve.

This is happening because you are using react-router version 2.0.0

Just enter "npm install --save react-router@3.2.0"

It should just work fine now.



来源:https://stackoverflow.com/questions/47184178/react-uncaught-typeerror-cannot-read-property-func-of-undefined

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