使用React路由器4以编程方式传递路由更改数据

时间:2017-09-29 12:16:08

标签: reactjs react-router react-redux react-router-v4 react-router-redux

要求是将某些数据传递给将在路由更改时呈现的组件(以编程方式)。目前我正在使用来自' react-router-redux'没有传递任何数据。

所以我正在导航到/ Animal并将特定动物细节传递给我希望URl显示的数据http://localhost/Animal

我正在使用React路由器4。

import {push} from 'react-router-redux';

export function changeRoute(newRoute, data) {
    return (dispatch) => dispatch(push(newroute));
}

如何实现这一目标?

1 个答案:

答案 0 :(得分:0)

您应该使用页面中的操作传递数据,并使用Animal页面中的相应reducer检索数据。

animalActions.setData(data);
animalActions.changeRoute(newRoute);

在动物页面中,

mapStateToProps =(state)=>{
    return{
     animalData:animalReducer.data
          }
}

然后您可以使用道具访问数据。

相关问题