ice/packages/route-manifest
ClarkXia b8e974393f
feat: support routes config (#5968)
* feat: support routes config

* fix: compatible with win32

* feat: add test case

* fix: optimize code

* fix: compatible with path

* Update routes.ts

* Update routes.ts
2023-02-28 10:00:43 +08:00
..
src feat: support routes config (#5968) 2023-02-28 10:00:43 +08:00
tests feat: support routes config (#5968) 2023-02-28 10:00:43 +08:00
CHANGELOG.md
README.md chore: optimize (#676) 2022-11-15 10:33:11 +08:00
package.json feat: use changeset to publish and version (#5864) 2023-02-13 14:48:34 +08:00
tsconfig.json

README.md

@ice/route-manifest

Generate route manifest based on the src directory in the project for ice.js 3.

API

generateRouteManifest(rootDir: string)

  • rootDir: the project directory absolute path

Will scan the page files in the rootDir and generate the routeManifest. For example:

const routeManifest = generateRouteManifest(__dirname);
console.log(routeManifest);
/**
[
  layout: {
    path: "",
    id: "layout",
    componentName: "Layout",
    file: "layout.tsx",
  },
  "pages/About/index": {
    path: "/About",
    index: true,
    id: "pages/About/index",
    parentId: "layout",
    file: "pages/About/index.tsx",
    componentName: "PagesAboutIndex",
  },
}
*/

formatNestedRouteManifest(routeManifest: RouteManifest)

  • routeManifest: generated by the generateRouteManifest function

It will get the nested route by the routeManifest. For example:

routeManifest:

const routeManifest = [
  layout: {
    path: "",
    id: "layout",
    componentName: "Layout",
    file: "layout.tsx",
  },
  "pages/About/index": {
    path: "/About",
    index: true,
    id: "pages/About/index",
    parentId: "layout",
    file: "pages/About/index.tsx",
    componentName: "PagesAboutIndex",
  },
}

const nestedRouteManifest = formatNestedRouteManifest(routeManifest);

console.log(nestedRouteManifest);
/**
[
  {
    path: "",
    id: "layout",
    componentName: "Layout",
    file: "layout.tsx",
    children: [
      {
        path: "/About",
        index: true,
        id: "pages/About/index",
        parentId: "layout",
        file: "pages/About/index.tsx",
        componentName: "PagesAboutIndex",
      },
    ]
  }
]
*/