React-router TypeError: _this.props.history is undefined

后端 未结 11 2176
旧时难觅i
旧时难觅i 2020-12-15 16:07

I am using react-router with react js and i following their documentation but facing this error

while compiling it shows the error,

TypeError: _this.         


        
11条回答
  •  没有蜡笔的小新
    2020-12-15 17:00

    I had something like:

    
       
       
       
       
     
    

    and AuthLayout was a component in which I was switching between SignIn and SignUp components, like below:

    { login ? : }

    I faced this error of this.props.history is not a function inside these components. It was because I hadn't used those components directly inside the router. I had access to this.props.history inside the AuthLayout and I had to pass it to its children.

    So I did it:

    { login ? : }

    and the problem solved.

提交回复
热议问题