Redux app状态通过url - >查询参数

Tim*_*ney 1 reactjs redux react-router-redux

使用https://github.com/reactjs/react-router-redux/

如果我想基于url查询params重新加载app(Redux)状态是获取state.routing.locationBeforeTransitions.query属性的正确方法吗?

在此输入图像描述

它的工作原理......只是想知道这是否正确.

Tim*_*ney 5

使用Redux连接组件,您可以从mapStateToProps的第二个参数访问路由器的props:

function mapStateToProps (state, ownProps) {
  return {
    num: state.items.num,
    query: ownProps.location.query
  }
}

export default connect(mapStateToProps, null)(YourComponent)
Run Code Online (Sandbox Code Playgroud)

请参阅https://github.com/reactjs/react-router-redux#user-content-how-do-i-access-router-state-in-a-container-component.

您还可以在这里查看演示https://github.com/timarney/react-router-redux-query-params.