ant-design / ant-design-pro

👨🏻‍💻👩🏻‍💻 Use Ant Design like a Pro!
https://pro.ant.design
MIT License
36.34k stars 8.14k forks source link

🧐[问题 | question]是否推荐动态路由 #11287

Open xli-cube opened 2 months ago

xli-cube commented 2 months ago

🧐 问题描述 | Problem description

从服务器端获取路由组件,并动态添加组件后,能正常路由到页面,但页面样式乱掉,没有继承layout的左侧菜单。ant官方是否有推荐的写法?

💻 示例代码 | Sample code

export async function patchClientRoutes({routes}: { routes: any[] }) { const DynamicComponent = React.lazy(() => import(@/pages/frame/ui/Module)); // 输出到控制台 console.log(route); // 输出找到的对象 routes.unshift( { id: '/frame/ui/Module', name:'Module', path: '/frame/ui/Module', element: (<React.Suspense fallback={

Loading...
}>

  </React.Suspense>) || <NotFound />,
});}

🚑 其他信息 | Other information