From 205dda088863ff30e333519e81e358dcc2fa085f Mon Sep 17 00:00:00 2001 From: fz6m <59400654+fz6m@users.noreply.github.com> Date: Sun, 17 Mar 2024 10:39:06 +0900 Subject: [PATCH] docs: compat with old hash anchors --- .../theme/builtins/HashAnchorCompat/index.tsx | 17 +++++++++++++++++ docs/docs/docs/api/runtime-config.md | 10 ++++++++++ 2 files changed, 27 insertions(+) create mode 100644 docs/.dumi/theme/builtins/HashAnchorCompat/index.tsx diff --git a/docs/.dumi/theme/builtins/HashAnchorCompat/index.tsx b/docs/.dumi/theme/builtins/HashAnchorCompat/index.tsx new file mode 100644 index 000000000000..0046d5bab1af --- /dev/null +++ b/docs/.dumi/theme/builtins/HashAnchorCompat/index.tsx @@ -0,0 +1,17 @@ +import { useLayoutEffect } from 'react'; + +interface IHashAnchorCompatProps { + from: string; + to: string; +} + +export default function HashAnchorCompat({ from, to }: IHashAnchorCompatProps) { + useLayoutEffect(() => { + const hash = window.location.hash; + if (hash === from) { + window.location.hash = to; + } + }, []); + + return null; +} diff --git a/docs/docs/docs/api/runtime-config.md b/docs/docs/docs/api/runtime-config.md index c2359b7b79fc..1f64f54b6aca 100644 --- a/docs/docs/docs/api/runtime-config.md +++ b/docs/docs/docs/api/runtime-config.md @@ -144,6 +144,8 @@ export const layout: RuntimeConfig = { ### onRouteChange + + - type: `(args: { routes: Routes; clientRoutes: Routes; location: Location; action: Action; basename: string; isFirst: boolean }) => void` 在初始加载和路由切换时做一些事情。 @@ -178,6 +180,8 @@ export function onRouteChange({ clientRoutes, location }) { ### patchRoutes + + - type: `(args: { routes: Routes; routeComponents }) => void` ```ts @@ -194,6 +198,8 @@ export function patchRoutes({ routes, routeComponents }) { ### patchClientRoutes + + - type: `(args: { routes: Routes; }) => void` 修改被 react-router 渲染前的树状路由表,接收内容同 [useRoutes](https://reactrouter.com/en/main/hooks/use-routes)。 @@ -270,6 +276,8 @@ Umi 内置了 `qiankun` 插件来提供微前端的能力,具体参考[插件 ### render + + - Type: `(oldRender: Function)=>void` 覆写 render。 @@ -294,6 +302,8 @@ export function render(oldRender) { ### rootContainer + + - Type: `(container: JSX.Element,args: { routes: Routes; plugin; history: History }) => JSX.Element;` 修改交给 react-dom 渲染时的根组件。