解析动态参数,获取信息
export function getCategory(path) {
let current = 1;
if (!path) {
return { ids: [], id: undefined, current: 1 };
}
// 切分路径
const ids = path.split('/');
if (!ids|| !ids.length) {
return { ids: [], id: undefined, current: 1 };
}
let pageReg = /^p[0-9]+$/;
if (pageReg.test(ids[ids.length - 1])) {
const currentStr = ids[ids.length - 1].replace('p', '');
const parseCurrent = parseInt(currentStr);
current = parseCurrent > 0 ?parseCurrent : 1
return { ids:ids.slice(0,ids.length-1), id: ids[0, ids.length - 2], current };
}
return { ids, id: ids[ids.length - 1], current: 1 };
}