Browse Source

修复动态路由编译不能正确访问

main
李金 6 months ago
parent
commit
78aaab2525
  1. 7
      src/routes.tsx

7
src/routes.tsx

@ -178,6 +178,10 @@ declare module '@tanstack/react-router' {
} }
} }
const modules = import.meta.glob('./pages/**/*.{jsx,tsx}')
console.log(modules)
const generateDynamicRoutes = (menuData: MenuItem[], parentRoute: AnyRoute) => { const generateDynamicRoutes = (menuData: MenuItem[], parentRoute: AnyRoute) => {
// 递归生成路由,如果有routes则递归生成子路由 // 递归生成路由,如果有routes则递归生成子路由
@ -223,7 +227,8 @@ const generateDynamicRoutes = (menuData: MenuItem[], parentRoute: AnyRoute) => {
return createRoute({ return createRoute({
...options, ...options,
component: lazyRouteComponent(() => import(`./pages/${component}`)),
// @ts-ignore fix import
component: lazyRouteComponent(() => (modules[`./pages/${component}/index.tsx`] || modules[`./pages/${component}/index.jsx`])?.()),
notFoundComponent: NotFound, notFoundComponent: NotFound,
}) })
} }

Loading…
Cancel
Save