解析动态参数,获取信息

    1. export function getCategory(path) {
    2. let current = 1;
    3. if (!path) {
    4. return { ids: [], id: undefined, current: 1 };
    5. }
    6. // 切分路径
    7. const ids = path.split('/');
    8. if (!ids|| !ids.length) {
    9. return { ids: [], id: undefined, current: 1 };
    10. }
    11. let pageReg = /^p[0-9]+$/;
    12. if (pageReg.test(ids[ids.length - 1])) {
    13. const currentStr = ids[ids.length - 1].replace('p', '');
    14. const parseCurrent = parseInt(currentStr);
    15. current = parseCurrent > 0 ?parseCurrent : 1
    16. return { ids:ids.slice(0,ids.length-1), id: ids[0, ids.length - 2], current };
    17. }
    18. return { ids, id: ids[ids.length - 1], current: 1 };
    19. }

    https://www.yuque.com/robinson/workdays/rn489l