{"id":21067025,"url":"https://github.com/zclzone/vite-plugin-generoutes","last_synced_at":"2026-01-16T20:59:23.410Z","repository":{"id":244563617,"uuid":"815595141","full_name":"zclzone/vite-plugin-generoutes","owner":"zclzone","description":"A Vite plugin that generates routes based on the file structure, supports dynamic routes, and supports custom meta data for each route.","archived":false,"fork":false,"pushed_at":"2026-01-14T08:25:11.000Z","size":336,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-14T12:16:46.220Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zclzone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-06-15T15:17:57.000Z","updated_at":"2026-01-14T09:56:52.000Z","dependencies_parsed_at":"2024-06-15T17:27:45.645Z","dependency_job_id":"feb0d445-a1c6-4e98-a5d5-68ff72a2234f","html_url":"https://github.com/zclzone/vite-plugin-generoutes","commit_stats":null,"previous_names":["zclzone/vite-plugin-generoutes"],"tags_count":28,"template":false,"template_full_name":null,"purl":"pkg:github/zclzone/vite-plugin-generoutes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zclzone%2Fvite-plugin-generoutes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zclzone%2Fvite-plugin-generoutes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zclzone%2Fvite-plugin-generoutes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zclzone%2Fvite-plugin-generoutes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zclzone","download_url":"https://codeload.github.com/zclzone/vite-plugin-generoutes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zclzone%2Fvite-plugin-generoutes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28482456,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T18:02:15.360Z","updated_at":"2026-01-16T20:59:23.383Z","avatar_url":"https://github.com/zclzone.png","language":"TypeScript","readme":"# vite-plugin-generoutes\n\nA Vite plugin that automatically generates Vue router configuration based on file system.\n\n### 📋 Prerequisites\n\n- **Node.js**: `20.12.0` or higher\n\n### ✨ Features\n\n- 📁 File-system based routing\n- 🔄 Dynamic and nested routes support\n- 🛠️ Hot reload - routes update when files change\n- 🎨 Customizable route configuration\n- 🧩 Support for route metadata via `defineOptions`\n- 🚦 Route redirection support\n- 🖼️ Layout-based route grouping\n\n### 📦 Installation\n\n```bash\n# npm\nnpm install vite-plugin-generoutes -D\n\n# yarn\nyarn add vite-plugin-generoutes -D\n\n# pnpm\npnpm add vite-plugin-generoutes -D\n```\n\n### 🔨 Usage\n\nConfigure the plugin in your `vite.config.js`:\n\n```javascript\nimport vue from '@vitejs/plugin-vue'\nimport { defineConfig } from 'vite'\nimport generoutes from 'vite-plugin-generoutes'\n\nexport default defineConfig({\n  plugins: [\n    vue(),\n    generoutes({\n      // options\n    })\n  ]\n})\n```\n\n### ⚙️ Configuration Options\n\n| Option          | Type       | Default          | Description                                                                                                       |\n| --------------- | ---------- | ---------------- | ----------------------------------------------------------------------------------------------------------------- |\n| `pagesFolder`   | `string`   | `'src/pages'`    | Path to pages folder                                                                                              |\n| `layoutsFolder` | `string`   | `'src/layouts'`  | Path to layouts folder                                                                                            |\n| `ignoreFolders` | `string[]` | `['components']` | Folders to ignore when generating routes                                                                          |\n| `routesPath`    | `string`   | Auto-detected    | Path to generated routes file. Auto-detected based on `tsconfig.json` presence (`.ts` if exists, otherwise `.js`) |\n\n### 📘 TypeScript Support\n\nThis plugin has first-class TypeScript support:\n\n- **Auto-detection**: Automatically detects TypeScript projects by checking for `tsconfig.json`\n- **Type definitions**: When generating routes for TypeScript projects, the plugin automatically includes type definitions for `RouteMeta` and `GeneratedRoute`\n- **Route typing**: Generated routes are properly typed with `RouteRecordRaw` from `vue-router`\n\n### 📝 Routing Conventions\n\n#### Basic Routes\n\n- `src/pages/index.vue` -\u003e `/`\n- `src/pages/about.vue` -\u003e `/about`\n- `src/pages/users/index.vue` -\u003e `/users`\n- `src/pages/users/profile.vue` -\u003e `/users/profile`\n\n#### Dynamic Routes\n\n- `src/pages/users/[id].vue` -\u003e `/users/:id`\n- `src/pages/users/[...all].vue` -\u003e `/users/:pathMatch(.*)*`\n- `src/pages/[org]/[repo].vue` -\u003e `/:org/:repo`\n\n#### Virtual Directories\n\n- Paths with parentheses in the filename are treated as virtual directories. The parenthesized part will be omitted in the generated route path.\n- For example: `src/pages/(auth)/login.vue` -\u003e `/login`\n\n### 🧠 Custom Routes\n\nYou can use `defineOptions` in your Vue files to customize route configuration:\n\n```vue\n\u003cscript setup\u003e\ndefineOptions({\n  name: 'CustomRouteName',\n  meta: {\n    title: 'Page Title',\n    icon: 'home',\n    requiresAuth: true,\n    enabled: true // Set to false to exclude this route\n  },\n  redirect: '/other-route' // Set redirection\n})\n\u003c/script\u003e\n```\n\n### 🌲 Nested Routes\n\nUse the `parent` property to set nested route relationships (handled automatically):\n\n```vue\n\u003cscript setup\u003e\ndefineOptions({\n  name: 'ChildRoute',\n  parent: 'ParentRouteName',\n  meta: {\n    title: 'Child Route'\n  }\n})\n\u003c/script\u003e\n```\n\n### �️ Layout Routes\n\nRoutes are automatically grouped by their `meta.layout` property and wrapped with a parent layout route:\n\n- Routes with `meta.layout: false` will **not** be wrapped with a layout\n- Routes without `meta.layout` will use the `'default'` layout by default\n- Routes with `meta.layout: 'xxx'` will use the corresponding layout component from `layoutsFolder`\n\n```vue\n\u003c!-- src/pages/login.vue - No layout wrapper --\u003e\n\u003cscript setup\u003e\ndefineOptions({\n  name: 'Login',\n  meta: {\n    layout: false\n  }\n})\n\u003c/script\u003e\n```\n\n```vue\n\u003c!-- src/pages/home.vue - Uses 'admin' layout --\u003e\n\u003cscript setup\u003e\ndefineOptions({\n  name: 'Home',\n  meta: {\n    layout: 'admin'\n  }\n})\n\u003c/script\u003e\n```\n\n**Generated route structure example:**\n\n```javascript\n[\n  // Routes with layout: false are not wrapped\n  {\n    name: 'Login',\n    path: '/login',\n    component: () =\u003e import('/src/pages/login.vue'),\n    meta: { layout: false }\n  },\n  // Routes are grouped by layout\n  {\n    name: 'LAYOUT_DEFAULT',\n    path: '/__layout_default__',\n    component: () =\u003e import('/src/layouts/default.vue'),\n    children: [\n      { name: 'Index', path: '/' }\n    ]\n  },\n  {\n    name: 'LAYOUT_ADMIN',\n    path: '/__layout_admin__',\n    component: () =\u003e import('/src/layouts/admin.vue'),\n    children: [\n      { name: 'Home', path: '/home' }\n    ]\n  }\n]\n```\n\n### �🚀 Complete Example\n\n```javascript\nimport vue from '@vitejs/plugin-vue'\nimport { defineConfig } from 'vite'\nimport generoutes from 'vite-plugin-generoutes'\n\nexport default defineConfig({\n  plugins: [\n    vue(),\n    generoutes({\n      pagesFolder: 'src/views',\n      ignoreFolders: ['components', 'assets'],\n      routesPath: 'src/router/routes.js'\n    })\n  ]\n})\n```\n\n### 💡 Troubleshooting\n\n**Issue**: Route path shows error: *Cannot find module \"/src/pages/xxx.vue\" or its corresponding type declarations.* Unable to navigate to the file with F12.\n\n**Solution**: Add the following configuration to the `compilerOptions` in your `jsconfig.json` or `tsconfig.json`:\n```json\n{\n  \"compilerOptions\": {\n    \"baseUrl\": \".\",\n    \"paths\": {\n      \"/src/*\": [\"src/*\"]\n    }\n  }\n}\n```\n\n[中文文档](./README.zh_CN.md)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzclzone%2Fvite-plugin-generoutes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzclzone%2Fvite-plugin-generoutes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzclzone%2Fvite-plugin-generoutes/lists"}