From 5d64b5c81048647c5804e90de3305d8f87d535a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=9F=E8=B4=A4?= Date: Mon, 19 Feb 2024 10:50:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E6=A1=A3=E6=96=B9?= =?UTF-8?q?=E4=BE=BF=E6=A3=80=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/docs/docs/api/runtime-config.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/docs/docs/api/runtime-config.md b/docs/docs/docs/api/runtime-config.md index 92da1930bf02..c2359b7b79fc 100644 --- a/docs/docs/docs/api/runtime-config.md +++ b/docs/docs/docs/api/runtime-config.md @@ -90,6 +90,8 @@ export default { ### getInitialState +- Type: `getInitialState: () => Promise | any` + `getInitialState()` 的返回值将成为全局初始状态。例如: ```ts @@ -124,6 +126,8 @@ export default function Page() { ### layout +- Type: `RuntimeConfig | ProLayoutProps` + 修改[内置布局](../max/layout-menu)的配置,比如配置退出登陆、自定义导航暴露的渲染区域等。 > 注意:需要开启 [layout](../api/config#layout) 插件,才能使用它的运行时配置。 @@ -131,14 +135,16 @@ export default function Page() { ```tsx import { RuntimeConfig } from 'umi'; -export const layout:RuntimeConfig = { +export const layout: RuntimeConfig = { logout: () => {}, // do something }; ``` 更多具体配置参考[插件文档](../max/layout-menu#运行时配置)。 -### onRouteChange(\{ routes, clientRoutes, location, action, basename, isFirst \}) +### onRouteChange + +- type: `(args: { routes: Routes; clientRoutes: Routes; location: Location; action: Action; basename: string; isFirst: boolean }) => void` 在初始加载和路由切换时做一些事情。 @@ -172,6 +178,8 @@ export function onRouteChange({ clientRoutes, location }) { ### patchRoutes +- type: `(args: { routes: Routes; routeComponents }) => void` + ```ts export function patchRoutes({ routes, routeComponents }) { console.log('patchRoutes', routes, routeComponents); @@ -186,6 +194,8 @@ export function patchRoutes({ routes, routeComponents }) { ### patchClientRoutes +- type: `(args: { routes: Routes; }) => void` + 修改被 react-router 渲染前的树状路由表,接收内容同 [useRoutes](https://reactrouter.com/en/main/hooks/use-routes)。 比如在最前面添加一个 `/foo` 路由, @@ -260,6 +270,8 @@ Umi 内置了 `qiankun` 插件来提供微前端的能力,具体参考[插件 ### render +- Type: `(oldRender: Function)=>void` + 覆写 render。 比如用于渲染之前做权限校验, @@ -282,6 +294,8 @@ export function render(oldRender) { ### rootContainer +- Type: `(container: JSX.Element,args: { routes: Routes; plugin; history: History }) => JSX.Element;` + 修改交给 react-dom 渲染时的根组件。 比如用于在外面包一个 Provider,