Skip to content

Commit

Permalink
优化文档方便检索
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Feb 19, 2024
1 parent 0a666fc commit 5d64b5c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions docs/docs/docs/api/runtime-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export default {

### getInitialState

- Type: `getInitialState: () => Promise<DataType extends any> | any`

`getInitialState()` 的返回值将成为全局初始状态。例如:

```ts
Expand Down Expand Up @@ -124,21 +126,25 @@ export default function Page() {

### layout

- Type: `RuntimeConfig | ProLayoutProps`

修改[内置布局](../max/layout-menu)的配置,比如配置退出登陆、自定义导航暴露的渲染区域等。

> 注意:需要开启 [layout](../api/config#layout) 插件,才能使用它的运行时配置。
```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`

在初始加载和路由切换时做一些事情。

Expand Down Expand Up @@ -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);
Expand All @@ -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` 路由,
Expand Down Expand Up @@ -260,6 +270,8 @@ Umi 内置了 `qiankun` 插件来提供微前端的能力,具体参考[插件

### render

- Type: `(oldRender: Function)=>void`

覆写 render。

比如用于渲染之前做权限校验,
Expand All @@ -282,6 +294,8 @@ export function render(oldRender) {
### rootContainer
- Type: `(container: JSX.Element,args: { routes: Routes; plugin; history: History }) => JSX.Element;`
修改交给 react-dom 渲染时的根组件。
比如用于在外面包一个 Provider,
Expand Down

0 comments on commit 5d64b5c

Please sign in to comment.