hashrouter刷新报错,this.props.location.state为undefined

我从A页面带参数跳转到B页面

this.props.history.push({ pathname: '/send_msg', state: { query: obj } })

此时在B页面能取到this.props.location.state
https://img1.mukewang.com/5c752f78000141fe04200486.jpg

但是刷新B页面,this.props.location.state就变成了undefined,求解如何处理?

https://img3.mukewang.com/5c752f8300018bd504040396.jpg


回首忆惘然
浏览 3054回答 2
2回答

绝地无双

刷新肯定会报错,因为你的参数是从前一个页面带过来的,正确的做法是用路由参数,可以放在 query 里边,这样参数保存在 url 里,就不怕刷新了

qq_遁去的一_1

这样试试,如楼上所说,放到query里var query = {         pathname: '/send_msg',         query: obj }this.props.history.push(query)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5