匹配到不同路径时,触发不同的effect
import pathToRegexp from 'path-to-regexp';
// 常量
const PAGE_ROUTE = {
MATERIAL_STORAGE: {
pathname: '/materialStorage',
},
FINANCIAL_PRODUCTS: {
pathname: '/financialProducts',
},
DETAIL_COPY: {
pathname: '/layout/copy/:layoutId',
},
}
...
setup({ dispatch, history }) {
return history.listen((props) => {
const { pathname, state } = props;
Object.entries(PAGE_ROUTE).forEach(([key, value]) => {
let matchResults = [];
const groups = pathToRegexp(value.pathname, matchResults).exec(pathname);
if (groups) {
let params = {};
matchResults.forEach(function (k, i) {
params[k.name] = groups[i + 1];
});
console.log('state', state);
dispatch({ type: 'detailIndexPage', payload: { layoutScheme: state, params } });
}
});
});
},