@@ -16,7 +16,21 @@ const PAGE_CANDIDATE_TEMPLATES = [
1616 ( path , ext ) => `/src/pages${ path } /index${ ext } ` ,
1717]
1818
19- const pageModules = import . meta?. glob ?. ( '/src/pages/**/*.{js,jsx,ts,tsx}' ) ?? { }
19+ // 兼容 Vite 和 Webpack:import.meta.glob 是 Vite 独有功能
20+ // 在 Webpack 构建中 import.meta 会是 undefined 或抛出错误
21+ const getPageModules = ( ) => {
22+ try {
23+ // 检查是否在 Vite 环境中
24+ if ( typeof import . meta !== 'undefined' && typeof import . meta. glob === 'function' ) {
25+ return import . meta. glob ( '/src/pages/**/*.{js,jsx,ts,tsx}' )
26+ }
27+ } catch {
28+ // Webpack 环境下 import.meta 可能会抛出错误
29+ }
30+ return { }
31+ }
32+
33+ const pageModules = getPageModules ( )
2034
2135const hasOwn = ( obj , key ) => obj != null && Object . hasOwn ( obj , key )
2236
@@ -413,10 +427,17 @@ const ProSecNav = ({ mode = 'inline', theme = 'light', onMenuClick }) => {
413427 showDeniedOnce ( selectedPath )
414428 return
415429 }
416- redirectTo ( selectedPath )
417- setIsOpenChange ( false )
418- onMenuClick ?. ( )
430+ // 使用 try-catch 包裹路由跳转,防止异步组件加载失败导致菜单卡死
431+ try {
432+ redirectTo ( selectedPath )
433+ setIsOpenChange ( false )
434+ onMenuClick ?. ( )
435+ } catch ( navError ) {
436+ console . error ( '路由跳转失败:' , navError )
437+ messageApi . error ( '页面加载失败,请刷新重试' )
438+ }
419439 } catch ( error ) {
440+ console . error ( '权限检查失败:' , error )
420441 showDeniedOnce ( selectedPath )
421442 }
422443 }
0 commit comments