【发布时间】:2016-11-20 01:41:27
【问题描述】:
我正在使用 react-router-redux,我有这样的路由
<Route path="/user/:userId" components={{ body: UserMaintenance }} />
在路由中加载userId参数对应的用户对象的推荐方式是什么?
我的想法(我是 react 和 redux 的新手)是在 UserMaintenance componentWillReceiveProps 方法中使用 userId 参数并将 FETCH_USER 操作发送到将加载到 state.currentUser 的商店。当 currentUser 参数因操作而更新时,UserMaintenance 组件将随之更新。
【问题讨论】:
-
你的提议会很好用!您还可以使用特定路由中的
onEnter钩子:github.com/reactjs/react-router/blob/master/docs/… -
干杯,看起来不错,如下所述。
标签: reactjs redux react-router-redux