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

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

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

此时在B页面能取到this.props.location.state
clipboard.png

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

clipboard.png

阅读 6.5k
2 个回答

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题