重写复现方法
This commit is contained in:
@@ -14,17 +14,40 @@ const constantRoutes: RouteRecordRaw[] = [
|
|||||||
name: 'Index',
|
name: 'Index',
|
||||||
component: () => import('@/views/sys/index.vue'),
|
component: () => import('@/views/sys/index.vue'),
|
||||||
meta: { requiresAuth: true }
|
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({
|
const router = createRouter({
|
||||||
history: createWebHistory(import.meta.env.BASE_URL),
|
history: createWebHistory(import.meta.env.BASE_URL),
|
||||||
routes: [...constantRoutes]
|
routes: [...constantRoutes, ...bizRoutes]
|
||||||
})
|
})
|
||||||
|
|
||||||
export default router
|
export default router
|
||||||
Reference in New Issue
Block a user