react 拍平菜单树结构数据转化为一个普通的单层js对象

转换前

export const routesList = [
  {
    id: "/",
    title: "系统公告",
    path: "/"
  },
  {
    id: "/portalHome",
    title: "首页",
    path: "/portalHome"
  },
  {
    title: "公司集成",
    id: "/home",
    path: "/home",
    children: [
      {
        id: "/home/user",
        path: "/home/user",
        title: "用户管理"
      },
      {
        id: "/home/role",
        path: "/home/role",
        title: "角色管理"
      },
      {
        id: "/home/auth",
        path: "/home/auth",
        title: "权限管理"
      },
      {
        id: "/home/bulletin",
        path: "/home/bulletin",
        title: "公告管理"
      },
    ],
  },
];

转换后:

{
	/: "系统公告",
	/home: "公司集成",
	/home/auth: "权限管理",
	/home/bulletin: "公告管理",
	/home/role: "角色管理

猜你喜欢

转载自blog.csdn.net/Amnesiac666/article/details/125926295