例如 /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變化了