React router pass props to route component

前端 未结 2 767
耶瑟儿~
耶瑟儿~ 2021-02-06 17:25

I\'m trying to pass props from my app.jsx to one of my route components using react router but I get the following error

TypeError: Cannot read property \

2条回答
  •  爱一瞬间的悲伤
    2021-02-06 17:47

    Here are few ways you can pass props to a route component.

    With the react-router v5, we can create routes by wrapping with a component, so that we can easily pass props to the desired component like this.

    
        
    
    

    Similarly, you can use the children prop in v5.

    } />
    

    If you are using react-router v4, you can pass it using the render prop.

     } />
    

    (originally posted at https://reactgo.com/react-router-pass-props/)

提交回复
热议问题