Jos*_*osh 10 reactjs react-router redux
我想onEnter
在路由加载时使用react-router的钩子检查我的redux存储中的变量.
根据文件,onEnter
:
...接收下一个路由器状态作为其第一个参数.该
replaceState
功能可用于触发向不同URL的转换.
没有商店通过.是否可以从此钩子中连接到redux存储?我已经尝试了各种各样的东西,但找不到实现这一目标的方法.
我正在使用的版本:
"react-redux": "^4.0.0",
"react-router": "1.0.0-rc1",
"redux": "^3.0.0",
Run Code Online (Sandbox Code Playgroud)
小智 12
让您路由一个将存储放在参数中的函数
export default (store) => {
return (
<Route handler={App} path="/">
<Route path="mypath" component={handler} onEnter={myHook(store)}>
<Route>
)
};
Run Code Online (Sandbox Code Playgroud)
在转换挂钩中执行相同操作
export const myHook = (store) => {
return (location, replaceWith) => {
// Do something with your store
}
};
Run Code Online (Sandbox Code Playgroud)
然后假设您在同一个文件中创建商店和路由器
const router = (
<Provider store={store}>
<Router history={history}>
{routes(store)}
</Router>
</Provider>
);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6491 次 |
最近记录: |