{"_id":"@dabobo/routes","_rev":"4-6023f395f32c2e01395006f2edd36bb0","name":"@dabobo/routes","dist-tags":{"latest":"2.0.1"},"versions":{"2.0.0":{"name":"@dabobo/routes","version":"2.0.0","keywords":["Front End Engineering Scaffold","Auto Generate Router","Router","Layout","Build","Webpack","React","Vue"],"author":{"name":"hrdesign@163.com"},"license":"MIT","_id":"@dabobo/routes@2.0.0","maintainers":[{"name":"woritd","email":"hrdesign@163.com"}],"homepage":"https://github.com/abcrun/dabobo-toolkit#readme","bugs":{"url":"https://github.com/abcrun/dabobo-toolkit/issues"},"dist":{"shasum":"016c3deb3fce9f147990792e4b8277040b4e17bb","tarball":"https://registry.npmjs.org/@dabobo/routes/-/routes-2.0.0.tgz","fileCount":2,"integrity":"sha512-b+gx0vcdw9LyjdRWA1ugIOPL6xDcUk+yTZ8fVGNcTfmhMjbCMO4/miURuoB/Vcel41wkJrWz16donRSJCRmc7A==","signatures":[{"sig":"MEUCIFSO4VK7aAotQfe+3wyr9oS97pAABaOgwlBiWjlMnnipAiEA9NUaAHP0OLdiHhb3Uut37DgtGHpuAsl0brOs9Wve2t0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":3850},"main":"index.js","_npmUser":{"name":"woritd","email":"hrdesign@163.com"},"repository":{"url":"git+https://github.com/abcrun/dabobo-toolkit.git","type":"git","directory":"packages/routes"},"_npmVersion":"10.8.2","description":"Create Routes For File Location","directories":{},"_nodeVersion":"20.18.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/routes_2.0.0_1740649359979_0.6078277751339651","host":"s3://npm-registry-packages-npm-production"}},"2.0.0-rc.1":{"name":"@dabobo/routes","version":"2.0.0-rc.1","keywords":["Front End Engineering Scaffold","Auto Generate Router","Router","Layout","Build","Webpack","React","Vue"],"author":{"name":"hrdesign@163.com"},"license":"MIT","_id":"@dabobo/routes@2.0.0-rc.1","maintainers":[{"name":"woritd","email":"hrdesign@163.com"}],"homepage":"https://github.com/abcrun/dabobo-toolkit#readme","bugs":{"url":"https://github.com/abcrun/dabobo-toolkit/issues"},"dist":{"shasum":"86dfd76b2fd545df8f539ab7d7ff9fad2c31e855","tarball":"https://registry.npmjs.org/@dabobo/routes/-/routes-2.0.0-rc.1.tgz","fileCount":4,"integrity":"sha512-bRJ+ogrTroIkPR7A+y94ZR97QcvmmcxaZQToiUjj4IMUfBEO6dg4096piB7ZTj18Ia/ZYpzHNjDEoOb5CS4BOg==","signatures":[{"sig":"MEUCIBHIyLDyVIrZf2/zs4Icurx1s9MFPMebzFYG1sqaXnl6AiEA4JDsACFNwhMY410tUi4vkaOzg/vmS+2aAn8p84g8Es8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":7790},"main":"index.js","types":"types/index.d.ts","gitHead":"bdfbd5d3cb2619af9436e93652f25155ff3d5fd1","_npmUser":{"name":"woritd","email":"hrdesign@163.com"},"repository":{"url":"git+https://github.com/abcrun/dabobo-toolkit.git","type":"git","directory":"packages/routes"},"_npmVersion":"10.8.2","description":"Create Routes That The Path Is The File Location","directories":{},"_nodeVersion":"20.18.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@types/webpack-env":"^1.18.8"},"_npmOperationalInternal":{"tmp":"tmp/routes_2.0.0-rc.1_1740722470206_0.7722120664494938","host":"s3://npm-registry-packages-npm-production"}},"2.0.0-rc.2":{"name":"@dabobo/routes","version":"2.0.0-rc.2","keywords":["Front End Engineering Scaffold","Auto Generate Router","Router","Layout","Build","Webpack","React","Vue"],"author":{"name":"hrdesign@163.com"},"license":"MIT","_id":"@dabobo/routes@2.0.0-rc.2","maintainers":[{"name":"woritd","email":"hrdesign@163.com"}],"homepage":"https://github.com/abcrun/dabobo-toolkit#readme","bugs":{"url":"https://github.com/abcrun/dabobo-toolkit/issues"},"dist":{"shasum":"e92d0e6935432876569c64ae0631862da320cd1f","tarball":"https://registry.npmjs.org/@dabobo/routes/-/routes-2.0.0-rc.2.tgz","fileCount":4,"integrity":"sha512-mbJ5zCQ5BOLe8W/8IcflPjX94HPzQ0XxQED8A4e3Vka52sdPW7vJhKoomRnw65okmbQm4hwatHjkPwtJ1b33Zg==","signatures":[{"sig":"MEUCIBcVj4xZTjC/kWYFyej7OjhN84hlo+QPCHgWWa3YFo+8AiEAikBIvgg+JWMmBGQjGC9Hg2nyNAG0J+qFHNhnCxo7bfQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":7999},"main":"index.js","types":"types/index.d.ts","gitHead":"a6f1bdcfd80ad65a598a19273ca19120a31a8f65","_npmUser":{"name":"woritd","email":"hrdesign@163.com"},"repository":{"url":"git+https://github.com/abcrun/dabobo-toolkit.git","type":"git","directory":"packages/routes"},"_npmVersion":"10.8.2","description":"Create Routes That The Path Is The File Location","directories":{},"_nodeVersion":"20.19.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"webpack-env":"^0.8.0"},"_npmOperationalInternal":{"tmp":"tmp/routes_2.0.0-rc.2_1764329009485_0.26905268421326434","host":"s3://npm-registry-packages-npm-production"}},"2.0.1":{"name":"@dabobo/routes","version":"2.0.1","description":"Create Routes That The Path Is The File Location","repository":{"type":"git","url":"git+https://github.com/abcrun/dabobo-toolkit.git","directory":"packages/routes"},"main":"index.js","types":"types/index.d.ts","author":{"name":"hrdesign@163.com"},"license":"MIT","publishConfig":{"access":"public"},"keywords":["Front End Engineering Scaffold","Auto Generate Router","Router","Layout","Build","Webpack","React","Vue"],"devDependencies":{"webpack-env":"^0.8.0"},"bugs":{"url":"https://github.com/abcrun/dabobo-toolkit/issues"},"_id":"@dabobo/routes@2.0.1","gitHead":"41846c20be3bf499d63205184c15c0e7d79c6431","homepage":"https://github.com/abcrun/dabobo-toolkit#readme","_nodeVersion":"20.19.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-u9y0e5f+Lpdc++Lpq1kbn30oeyWI7rH+EqxWrP9MVkta5mC0ZCXLm9PqmCELl5C8KOPwWzElo4p5BRWbHqB7mw==","shasum":"f4e6ea024b28b584ce68ace0e0180eebd8ea87a5","tarball":"https://registry.npmjs.org/@dabobo/routes/-/routes-2.0.1.tgz","fileCount":4,"unpackedSize":8646,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIAG3eCjzkPCNa45twvK3TiyO3mxsMj6yl0fUmOcHiDYaAiB+XduyoUmIF0vnJB/xLjs035XawSQfNL/DKYGSNqiENA=="}]},"_npmUser":{"name":"woritd","email":"hrdesign@163.com"},"directories":{},"maintainers":[{"name":"woritd","email":"hrdesign@163.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/routes_2.0.1_1767761849421_0.018147205856332782"},"_hasShrinkwrap":false}},"time":{"created":"2025-02-27T09:42:39.874Z","modified":"2026-01-07T04:57:29.807Z","2.0.0":"2025-02-27T09:42:40.169Z","2.0.0-rc.1":"2025-02-28T06:01:10.420Z","2.0.0-rc.2":"2025-11-28T11:23:29.653Z","2.0.1":"2026-01-07T04:57:29.575Z"},"bugs":{"url":"https://github.com/abcrun/dabobo-toolkit/issues"},"author":{"name":"hrdesign@163.com"},"license":"MIT","homepage":"https://github.com/abcrun/dabobo-toolkit#readme","keywords":["Front End Engineering Scaffold","Auto Generate Router","Router","Layout","Build","Webpack","React","Vue"],"repository":{"type":"git","url":"git+https://github.com/abcrun/dabobo-toolkit.git","directory":"packages/routes"},"description":"Create Routes That The Path Is The File Location","maintainers":[{"name":"woritd","email":"hrdesign@163.com"}],"readme":"# @dabobo/routes\n\n## 描述\n`@dabobo/routes` 是一个用于根据文件路径自动生成路由的工具。\n\n## 安装\n使用 npm 安装：\n\n```sh\nnpm install @dabobo/routes\n```\n\n## 使用方法\n\n\n在您的项目中导入并使用 `createRoutes` 函数：\n\n```js\nimport createRoutes from '@dabobo/routes';\n\n// 示例 context\nconst context = require.context('./pages', true, /\\.page\\.js$/);\n// const context = import.meta.glob('./views/**/*.vue');\n\n// 创建路由，使用interceptor拦截和修改每个路由信息\nconst { routes, routesTreeArray } = createRoutes(context, (route) => {\n    // 可在此处对每个路由对象进行自定义处理\n    // 例如：添加meta信息，或修改component对象等\n    return {\n        ...route,\n        meta: { requiresAuth: true },\n    };\n});\n\nconsole.log(routes);\nconsole.log(routesTreeArray);\n```\n\n## API\n\n\n`createRoutes(context, [reg], [interceptor])`\n\n\n##### 参数\n\n* `context`：Webpack 的 `require.context` 对象。\n* `reg` (可选)：正则表达式，用于过滤文件。\n* `interceptor` (可选)：拦截器函数，接收每个路由信息（包含 path、id、key、parentId、redirect、component 等），可对其进行修改并返回新的路由对象。\n\n> ⚠️ 说明：如果只传递一个函数作为第二参数，则会被视为 `interceptor`。\n\n##### 返回值\n\n* `routes`：树形结构的路由数组。\n* `routesTreeArray`：扁平化的路由数组。\n\n## 文件夹特殊命名规则\n\n* `__layout`：以 `__layout` 结尾的文件会被视为其相应目录下的共用布局组件。例如，`/user/__layout.js` 会被应用到 `/user` 目录下的所有路由。\n* `$id`：以 `$` 开头的文件夹会被转换成 `:`，用于动态路由参数。例如，`/user/$id/profile.js` 会被转换成 `/user/:id/profile`。\n\n## 示例\n\n假设项目结构如下：\n\n```\nsrc/\n  pages/\n    __layout.js\n    index.js\n    about.js\n    user/\n      __layout.js\n      $id/\n        profile.js\n```\n\n使用 `createRoutes` 函数生成的 `routes` 结构如下：\n\n```js\n[\n    {\n        path: '/',\n        id: 1,\n        key: './__layout.js',\n        parentId: null,\n        redirect: '/index',\n        component, // 依赖于handler\n        children: [\n            {\n                path: '/index',\n                id: 2,\n                key: './index.js',\n                parentId: 1,\n                redirect: null,\n                component, // 依赖于handler\n                children: [],\n            },\n            {\n                path: '/about',\n                id: 3,\n                key: './about.js',\n                parentId: 1,\n                redirect: null,\n                component, // 依赖于handler\n                children: [],\n            },\n            {\n                path: '/user',\n                id: 4,\n                key: './user/__layout.js',\n                parentId: 1,\n                redirect: null,\n                component, // 依赖于handler\n                children: [\n                    {\n                        path: '/user/:id/profile',\n                        id: 5,\n                        key: './user/$id/profile.js',\n                        parentId: 4,\n                        component, // 依赖于handler\n                        children: [],\n                    }\n                ],\n            },\n        ]\n    }\n]\n```\n\n## 许可证\nMIT","readmeFilename":"README.md"}