nunjucks模板引擎yaml配置语法
mock.js模拟数据
roading
umi配置静态和动态路由
权限和动画
nmi实现原理
dva创建应用
集成AntdPro
定义路由和UI组件
链接仓库
使用effects和reducers
企业级后台系统 AntdPro

umi主应用

iceStark主应用接入 https://micro-frontends.ice.work/docs/guide/use-layout/react

  1. pnpm add @ice/stark

Prolayout 主应用布局

layout.childrenRender: (dom, props) => ,

  1. /**
  2. * 运行时配置
  3. * https://umijs.org/docs/api/runtime-config#dva
  4. */
  5. import { useState } from 'react';
  6. import { MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons';
  7. import dayjs from 'dayjs'
  8. import 'dayjs/locale/zh-cn';
  9. // import type { RunTimeLayoutConfig } from '@umijs/max';
  10. import { DEFAULT_NAME } from '@/constants';
  11. import Settings from '../config/defaultSettings';
  12. import MicroApp from './MicroApp'
  13. dayjs.locale('zh-cn')
  14. const purePath = [
  15. '/uicomponent',
  16. '/designer',
  17. 'publish'
  18. ]
  19. /**
  20. * 全局初始化数据配置,用于 Layout 用户信息和权限初始化
  21. * 文档:https://next.umijs.org/docs/api/runtime-config#getinitialstate
  22. */
  23. export async function getInitialState(): Promise<{ name: string }> {
  24. return { name: DEFAULT_NAME };
  25. }
  26. export const layout = ({ initialState }: any) => {
  27. // eslint-disable-next-line react-hooks/rules-of-hooks
  28. const [collapsed, setCollapsed] = useState(false);
  29. return {
  30. ...Settings,
  31. pure: !!purePath.find(it => window.location.pathname.includes(it)),
  32. logo: 'https://img.alicdn.com/tfs/TB1YHEpwUT1gK0jSZFhXXaAtVXa-28-27.svg',
  33. menu: {
  34. locale: false,
  35. type: 'group', // 菜单分组
  36. },
  37. avatarProps: {
  38. src: 'https://gw.alipayobjects.com/zos/antfincdn/efFD%24IOql2/weixintupian_20170331104822.jpg',
  39. size: 'small',
  40. title: 'lulongwen',
  41. },
  42. breakpoint: false,
  43. // 关闭默认的折叠按钮
  44. collapsedButtonRender: false,
  45. collapsed,
  46. onCollapse: (flag: boolean) => setCollapsed(flag),
  47. headerContentRender: () => {
  48. return (
  49. <div className="header-render">
  50. {collapsed
  51. ? <MenuUnfoldOutlined onClick={() => setCollapsed(!collapsed)} />
  52. : <MenuFoldOutlined onClick={() => setCollapsed(!collapsed)} />}
  53. </div>
  54. );
  55. },
  56. menuFooterRender: (props: any) => {
  57. if (props?.collapsed) return undefined;
  58. return (
  59. <p
  60. style={{
  61. textAlign: 'center',
  62. paddingBlockStart: 12,
  63. }}
  64. >
  65. Power by {DEFAULT_NAME}
  66. </p>
  67. );
  68. },
  69. bgLayoutImgList: [
  70. {
  71. src: 'https://img.alicdn.com/imgextra/i2/O1CN01O4etvp1DvpFLKfuWq_!!6000000000279-2-tps-609-606.png',
  72. left: 85,
  73. bottom: 100,
  74. height: '303px',
  75. },
  76. {
  77. src: 'https://img.alicdn.com/imgextra/i2/O1CN01O4etvp1DvpFLKfuWq_!!6000000000279-2-tps-609-606.png',
  78. bottom: -68,
  79. right: -45,
  80. height: '303px',
  81. },
  82. {
  83. src: 'https://img.alicdn.com/imgextra/i3/O1CN018NxReL1shX85Yz6Cx_!!6000000005798-2-tps-884-496.png',
  84. bottom: 0,
  85. left: 0,
  86. width: '331px',
  87. },
  88. ],
  89. childrenRender: (dom, props) => <MicroApp {...props} />,
  90. };
  91. };
  92. // export function onRouteChange({ location, clientRoutes, routes, action, basename }: any) {
  93. // console.log(800, location, clientRoutes, routes, action, basename);
  94. // }

childrenRender

�src/.umi/plugin-layout/Layout.tsx
umijs的文档中没有自定义 pageContainer的说明,需要自己看 plugin-layout插件
image.png

rootContainer

rootContainer 可以渲染子应用,但是没有主应用的布局

  1. export function rootContainer(container) {
  2. return React.createElement(MicroApp, null, container);
  3. }