How do I clear location.state in react-router on page reload?

前端 未结 4 1897
余生分开走
余生分开走 2021-01-03 23:01

I am currently passing my state on route change like below:



        
4条回答
  •  南笙
    南笙 (楼主)
    2021-01-03 23:15

    I would suggest not to use the location prop here, but to create a Route (wherever you define them) with a path: /transactions/:transactionId, and to catch the transactionId in the prop props.match.params.transactionId inside of the target component. Then in the componentDidMount you can dispatch the API request action in order to fetch the transaction. Don't forget to delete the state param from the props of the Link.

提交回复
热议问题