Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: compat with old hash anchors #12211

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading