Subscriptions:(Modal)
Subscription 语义是订阅,用于订阅一个数据源,然后根据条件 dispatch 需要的 action。数据源可以是当前的时间、服务器的 websocket 连接、keyboard 输入、geolocation 变化、history 路由变化等等。
例:(监听路由变化,一旦跳转到'/treatRecord'页面,dispatch reducers的中改变当前页方法)
import pathToRegexp from 'path-to-regexp';(yarn add path-to-regexp )具体使用:https://www.jianshu.com/p/7d2dbfdd1b0f
pathToRegexp : 匹配规则 exec:匹配 url 地址与规则是否相符
setup是方法名,可以随便取
使用的情况:1、当路由跳转到指定页面时可以操作
subscriptions: {
setup({ dispatch, history }) {//setup方法名,随便取
history.listen(({ pathname,query }) => {
const match = pathToRegexp('/treatRecord').exec(pathname)//监听路由
if (match) {
dispatch({ type: 'rupdateCurrent', payload: 1 })//一旦符合就修改页面为第一页
}
})
},
},
2、只要路由跳转,就执行操作(modal改变,connect的页面也会自动刷新)
subscriptions: {
setupHeader({ dispatch, history }) {
history.listen(({ pathname, query }) => {
dispatch({
type: 'getAeRecList',
payload: {
page: 1,
rows: 10,
}
});
})
},
},