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

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

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



        
4条回答
  •  再見小時候
    2021-01-03 23:18

    There is better approach without using the 3 party library.

    We can use history.replace()

    https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/api/history.md

    componentDidMount(){
     const {location,history} = this.props;
     //use the state via location.state
     //and replace the state via
     history.replace() 
    }
    

提交回复
热议问题