获取菜单数组的 path,最后返回的数据
    [“/dashboard”, “/dashboard/analysis”, “/dashboard/analysis/realtime”, “/dashboard/analysis/offline”, “/list”]

    原始的数据

    1. const data = [
    2. {
    3. name: '仪表盘',
    4. icon: 'dashboard',
    5. path: '/dashboard', // before is 'dashboard'
    6. children: [
    7. {
    8. name: '分析页',
    9. path: '/dashboard/analysis', // before is 'analysis'
    10. children: [
    11. {
    12. name: '实时数据',
    13. path: '/dashboard/analysis/realtime', // before is 'realtime'
    14. },
    15. {
    16. name: '离线数据',
    17. path: '/dashboard/analysis/offline', // before is 'offline'
    18. },
    19. ],
    20. },
    21. ],
    22. },
    23. {
    24. name: '列表页',
    25. icon: 'list',
    26. path: '/list',
    27. },
    28. ];

    打平数组菜单的 path

    1. export function getFlatMenuKeys(menuData) {
    2. return menuData.reduce((keys, item) => {
    3. const {children, path} = item;
    4. keys.push(path);
    5. if (children && children.length) {
    6. return keys.concat(getFlatMenuKeys(children));
    7. }
    8. return keys;
    9. }, [])
    10. }
    1. const nestedMenu = [
    2. {
    3. path: "/dashboard",
    4. children: [
    5. {
    6. path: "/dashboard/analysis",
    7. children: [
    8. { path: "/dashboard/analysis/realtime" },
    9. { path: "/dashboard/analysis/offline" },
    10. ],
    11. },
    12. { path: "/dashboard/monitor" },
    13. ],
    14. },
    15. { path: "/user" },
    16. { path: "/form" },
    17. ];
    18. // 输出
    19. [
    20. '/dashboard',
    21. '/dashboard/analysis',
    22. '/dashboard/analysis/realtime',
    23. '/dashboard/analysis/offline',
    24. '/dashboard/monitor',
    25. '/user',
    26. '/form',
    27. ]