重写复现方法

This commit is contained in:
2025-09-02 17:31:44 +08:00
parent 108534a964
commit c555bbba1d

View File

@@ -14,17 +14,40 @@ const constantRoutes: RouteRecordRaw[] = [
name: 'Index',
component: () => import('@/views/sys/index.vue'),
meta: { requiresAuth: true }
},
{
path: '/biz/data/index', // 路由PATH与chref对应
name: 'DataIndex',
component: () => import('@/biz/data/index.vue') // 对应的组件
}
]
/* 2. 自动扫描 views/biz 下的所有 .vue 文件 */
const bizModules = import.meta.glob('../views/biz/**/*.vue')
const bizRoutes: RouteRecordRaw[] = Object.entries(bizModules).map(
([filePath, asyncComp]) => {
// filePath 形如 ../views/biz/order/List.vue
// 去掉前缀和扩展名,得到 biz/order/List
const routePath = filePath
.replace('../views/biz/', '')
.replace('.vue', '')
.split('/')
.join('/')
// 路由名:把路径转成 PascalCase例如 OrderList
const routeName = routePath
.split('/')
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
.join('')
return {
path: `/biz/${routePath}`.replace(/\/+/g, '/'), // 防止双斜杠
name: routeName || 'BizIndex',
component: asyncComp
}
}
)
/* 3. 合并路由 */
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [...constantRoutes]
routes: [...constantRoutes, ...bizRoutes]
})
export default router