Warning: Failed propType: Invalid prop `component` supplied to `Route`

后端 未结 11 817
礼貌的吻别
礼貌的吻别 2020-12-29 01:09

I\'m trying new react-router 1.0.0 and I\'m getting strange warnings I can\'t explain:

Warning: Failed propType: Invalid prop `component` supplied to `Ro

相关标签:
11条回答
  • 2020-12-29 01:31

    This is definitely a syntax issue, when it happened to me I discovered I typed

    module.export = Component; instead of module.exports = Component;

    0 讨论(0)
  • 2020-12-29 01:35

    There is an stable release on the react-router-dom (v5) with the fix for this issue.

    link to github issue

    0 讨论(0)
  • 2020-12-29 01:39

    I solved this issue by doing this:

    instead of

    <Route path="/" component={HomePage} />
    
    

    do this

    <Route
     path="/" component={props => <HomePage {...props} />} />
    
    0 讨论(0)
  • 2020-12-29 01:39

    This question is a bit old, but for those still arriving here now and using react-router 4.3 it's a bug and got fixed in the beta version 4.4.0. Just upgrade your react-router to version +4.4.0. Be aware that it's a beta version at this moment.

    yarn add react-router@next
    

    or

    npm install -s react-router@4.4.0-beta.8
    
    0 讨论(0)
  • 2020-12-29 01:44

    In some cases, such as routing with a component that's wrapped with redux-form, replacing the Route component argument on this JSX element:

    <Route path="speaker" component={Speaker}/>
    

    With the Route render argument like the following, will fix issue:

    <Route path="speaker" render={props => <Speaker {...props} />} />
    
    0 讨论(0)
提交回复
热议问题