例如 /AAA/id的页面
AAA变化时路由跳转很好写,当只点击其id文章变化后,地址栏id变化了,但页面没有刷新变化,所以加一个监听函数subscriptions
首先npm install path-to-regexp
然后在该列表页AAA里的models层找到接受数据页
import pathToRegexp from 'path-to-regexp';
在effects后写上
subscriptions: {
setup({ dispatch, history }) {
history.listen(({ pathname }) => {
const path = pathToRegexp('/AAA/:id').exec(pathname);
if (pathname === '/AAA') {
dispatch({
type: 'fetchList',//这里的fetchlist就是你effects里请求接口获取数据的函数名
payload: {},
});
}
if (path) {
dispatch({
type: 'content/fetchDetail',//这里的content/fetchDetail就是该id页内models层对应内容页里effects里请求接口获取数据的函数名
payload: path[1],
});
}
});
},
},
以上写完后,其他该怎么写还是正常写,不变,只是加上这段就能监听id变化了