怎么让route拥有redux的方法
来源:互联网 发布:软件工程设计原则 编辑:程序博客网 时间:2024/05/01 20:07
需求
如何利用route的onEnter钩子来出发redux的dispatch
方法
I just wrapped my routes in a function that returns them.
This allows you to pass the redux store as an argument
Any onEnter/onExit functions are also defined in there so they have access to that store argument and can dispatch() stuff.
route的配置本质上只要是下面这样,然后在放到router里就可以了。
//route.jsexport default(<Route path="/" component={Index}> <IndexRoute component={Index} /> <Route path="/public" component={PublicArea} /></Route>)//main.jsimport route from './route.js'import {Router} from 'react-router';ReactDom.render( <Provider store={store}> <Router history={history}>{router}</Router> </Provider>, app);
那么既然只要是像route.js
那样的格式就行了,我也可以把route.js
写成一个函数,然后用函数来返回<route>
这些路由配置就可以了。
//route.jsexport default function(store){ doSth(store){ //doSth by store } return ( <Route path="/" component={Index}> <IndexRoute component={Index} /> <Route path="/public" component={PublicArea} /> </Route> )}//main.jsReactDom.render( <Provider store={store}> <Router history={history}>{router(store)}</Router> </Provider>, app);
参考资料:http://stackoverflow.com/questions/33643290/how-do-i-get-a-hold-of-the-store-dispatch-in-react-router-onenter
0 0
- 怎么让route拥有redux的方法
- linux怎么让普通用户拥有管理员权限
- 21个让你拥有更多时间的方法
- 25种方法让你成为拥有财富的人
- react-redux的connect()方法
- 10个有效的方法让你拥有更好的生活
- 让你的头脑达到顶尖效率的20种方法,你值得拥有!
- 怎么拥有36小时的一天
- 拥有自己的网站,怎么做!
- 怎么去拥有一夏天的风~
- 新的开始,让我拥有
- 让Notepad++拥有快速保存的功能
- 让网页超链接拥有多姿多彩的下划线
- 让程序拥有xp的风格
- 让Applet拥有更高的访问权限
- 让你的电脑拥有四个桌面
- 让你的Lable拥有qq表情!
- 让GridView拥有Grallery拖动的功能
- PAT(A) - 1024. Palindromic Number (25)
- Smart Install Maker制作安装包自动填写环境变量
- ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 的解决方法
- 设备 VMnet0 上的网络桥接当前未在运行。
- 字节序(大小端)详解从高低地址和高低位开始理解
- 怎么让route拥有redux的方法
- C语言关键字之typedef的使用
- [笔记] C++基础
- I2C详解
- CentOS 6.5 不覆盖 py2.x 安装 Python3.3.2
- cookie,session,locastorage等总结之session篇
- 1037. Magic Coupon (25)
- 数组的插入排序和快速排序
- HashTable, HashSet, HashMap的区别