Skip to content

Commit

Permalink
docs: compat with old hash anchors (#12211)
Browse files Browse the repository at this point in the history
  • Loading branch information
fz6m authored Mar 18, 2024
1 parent 849caed commit 8bfd4c7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/.dumi/theme/builtins/HashAnchorCompat/index.tsx
Original file line number Diff line number Diff line change
@@ -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;
}
10 changes: 10 additions & 0 deletions docs/docs/docs/api/runtime-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ export const layout: RuntimeConfig = {

### onRouteChange

<HashAnchorCompat from="#onroutechange-routes-clientroutes-location-action-basename-isfirst-" to="#onroutechange"></HashAnchorCompat>

- type: `(args: { routes: Routes; clientRoutes: Routes; location: Location; action: Action; basename: string; isFirst: boolean }) => void`

在初始加载和路由切换时做一些事情。
Expand Down Expand Up @@ -178,6 +180,8 @@ export function onRouteChange({ clientRoutes, location }) {

### patchRoutes

<HashAnchorCompat from="#patchroutes-routes-" to="#patchroutes"></HashAnchorCompat>

- type: `(args: { routes: Routes; routeComponents }) => void`

```ts
Expand All @@ -194,6 +198,8 @@ export function patchRoutes({ routes, routeComponents }) {

### patchClientRoutes

<HashAnchorCompat from="#patchclientroutes-routes-" to="#patchclientroutes"></HashAnchorCompat>

- type: `(args: { routes: Routes; }) => void`

修改被 react-router 渲染前的树状路由表,接收内容同 [useRoutes](https://reactrouter.com/en/main/hooks/use-routes)
Expand Down Expand Up @@ -270,6 +276,8 @@ Umi 内置了 `qiankun` 插件来提供微前端的能力,具体参考[插件

### render

<HashAnchorCompat from="#renderoldrender-function" to="#render"></HashAnchorCompat>

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

覆写 render。
Expand All @@ -294,6 +302,8 @@ export function render(oldRender) {
### rootContainer
<HashAnchorCompat from="#rootcontainerlastrootcontainer-args" to="#rootcontainer"></HashAnchorCompat>
- Type: `(container: JSX.Element,args: { routes: Routes; plugin; history: History }) => JSX.Element;`
修改交给 react-dom 渲染时的根组件。
Expand Down

0 comments on commit 8bfd4c7

Please sign in to comment.