【发布时间】:2016-06-15 01:04:32
【问题描述】:
我的“store.js”执行以下操作:
export default function configureStore(initialState = {todos: [], floatBar: {} }) {
return finalCreateStore(rootReducer, initialState)
}
然后在我的“client.js”中,我有初始化状态,但没有定义“todos”数组,并设置了路由器:
let initialState = {
floatBar: {
barStatus: false,
id: 0
}
}
let store = configureStore(initialState)
render(
<div>
<Provider store={store}>
<Router history={hashHistory}>
<Route
path="/"
component={App}
>
<Route
component={FirstPage}
path="firstpage"
/>
<Route
component={NewPage}
path="/newpage/:id"
/>
</Route>
</Router>
</Provider>
</div>,
document.getElementById('app')
)
然后在我的“item.js”组件中,它是“FirstPage.js”的子组件,它获取一个对象“todo”并检索“.id”,它是来自“todos”对象的一个对象-数组(在 render() return{} 内),我有以下内容:
<Link to={`/newpage/${this.props.todo.id}`}>Link1</Link>
最后,在我新链接的页面“NewPage.js”中,我希望能够在“item.js”中使用相同的“todo”对象,因此我可以调用“todo.id”等。我该怎么做?
谁能展示使用 redux react-router 的正确方法?真的很感激。
**更新
**最新的操作更新
actions.js 里面有我所有的动作创建者:
import * as actions from '../redux/actions'
class NewPage extends Component{
handleCommentChange(){
this.props.actions.updateComment()
}
render(){
return()
}
}
function mapDispatchToProps(dispatch){
return{
actions: bindActionCreators(actions, dispatch)
}
}
export default connect(
mapDispatchToProps
)(NewPage);
【问题讨论】:
标签: javascript reactjs redux react-router react-jsx