ice/packages/route-manifest
ClarkXia fac9889f84
chore: update versions (#7017)
* chore: update versions

* chore: update package.json

* Update CHANGELOG.md
2024-11-18 11:59:10 +08:00
..
src feat: improve miniapp (#6985) 2024-11-11 14:41:31 +08:00
tests feat: support define route with absolute path (#6467) 2023-08-21 13:49:43 +08:00
CHANGELOG.md chore: update versions (#7017) 2024-11-18 11:59:10 +08:00
README.md chore: optimize (#676) 2022-11-15 10:33:11 +08:00
package.json chore: update versions (#7017) 2024-11-18 11:59:10 +08:00
tsconfig.json feat: router (#28) 2022-11-14 18:49:43 +08:00

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",
      },
    ]
  }
]
*/