React-router: TypeError: Cannot set property 'props' of undefined

前端 未结 2 1286
既然无缘
既然无缘 2020-12-10 02:02

I am trying to set up routing in Meteor using react-router package and have encountered the following TypeError:

相关标签:
2条回答
  • 2020-12-10 02:51

    Assuming you are importing Component as a React.Component correctly, try removing the parenthesis after Component.

    Should be:

    class Portfolio extends Component {
    

    instead of:

    class Portfolio extends Component () {
    

    If not, replace Componentwith React.Component.

    0 讨论(0)
  • 2020-12-10 02:58

    The answer provided by kctang is right, that
    use :

    class Portfolio extends Component {
    

    instead of:

    class Portfolio extends Component () {}
    

    I wanna add the cause of it ?? In object-oriented programing it's called inheritance, when you extend/inherit a class to use its component, you called by its name and it's not function. here you extend Component class not function, that's why you don't use parenthesis and also function need a parameter.

    0 讨论(0)
提交回复
热议问题