//从后端获得了这样的对象
const item = {
id: 37,
code: '11111',
parent: '22222',
ancestor: '33333',
name: 'attackDefenseView',
path: '/attackDefenseView',
sort: 1,
component: '/view/attackDefense/index',
hidden: false,
open: false,
enable: true,
cache: false,
icon: 'gongfangpingtai',
selected: false,
title: '攻防平台',
type: 'page',
created: 1725350026,
updated: 1725945660,
have: true,
}
//然后把它处理成路由
const newItem = {
path: item.path,
component: () =>
import(/* @vite-ignore */ ../..${item.component}.vue),
name: item.name,
meta: {
title: item.title,
icon: item.icon,
hidden: item.hidden,
},
children: null,
redirect: null,
},
//最后添加路由
router.addRoute(newItem )
这样做的话在dev环境下是没问题的,但是在build打包后,会报错Failed to load resource: the server responded with a status of 404 (Not Found)和TypeError: Failed to fetch dynamically imported module: http://127.0.0.1:5500/view/attackDefense/index.vue
尝试过去掉.vue或者改成.js,都不行
问题应该是出在component上,求解