From e667fa95e4c57b63791bb2d131c4855f3b8aa0ef Mon Sep 17 00:00:00 2001 From: Avan Date: Tue, 29 Oct 2024 17:58:04 +0800 Subject: [PATCH] fix: unable to jump page (#6772) --- .../components/Main/MainSection/index.tsx | 13 +++++++++++-- docs/components/components/Main/index.tsx | 11 +++++++---- docs/utils/index.ts | 15 +++++++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 docs/utils/index.ts diff --git a/docs/components/components/Main/MainSection/index.tsx b/docs/components/components/Main/MainSection/index.tsx index 1cdc5d283f..b45b7993de 100644 --- a/docs/components/components/Main/MainSection/index.tsx +++ b/docs/components/components/Main/MainSection/index.tsx @@ -2,6 +2,7 @@ import { Button } from 'antd-mobile' import React, { useEffect, useState } from 'react' import Lottie from 'react-lottie' import { useTrans } from '../../../../hooks/useTrans' +import { openUrl } from '../../../../utils' import styles from './index.local.less' export default (props: { isWidthScreen: boolean }) => { @@ -39,7 +40,11 @@ export default (props: { isWidthScreen: boolean }) => { color='primary' shape='rounded' className={styles.buttonLeft} - href={trans('/guide/quick-start', '/zh/guide/quick-start')} + onClick={() => + openUrl({ + href: trans('/guide/quick-start', '/zh/guide/quick-start'), + }) + } > {trans('Get Start', '开始使用')} @@ -47,7 +52,11 @@ export default (props: { isWidthScreen: boolean }) => { color='primary' shape='rounded' className={styles.buttonRight} - href={trans('/components', '/zh/components')} + onClick={() => + openUrl({ + href: trans('/components', '/zh/components'), + }) + } > {trans('Preview Online', '在线体验')} diff --git a/docs/components/components/Main/index.tsx b/docs/components/components/Main/index.tsx index 72858027d7..9187d6974e 100644 --- a/docs/components/components/Main/index.tsx +++ b/docs/components/components/Main/index.tsx @@ -4,6 +4,7 @@ import { Button, Card } from 'antd-mobile' import React, { useEffect, useRef, useState } from 'react' import Lottie from 'react-lottie' import { useTrans } from '../../../hooks/useTrans' +import { openUrl } from '../../../utils' import MainSection from './MainSection' import { getGuides, @@ -99,10 +100,12 @@ export default () => { diff --git a/docs/utils/index.ts b/docs/utils/index.ts new file mode 100644 index 0000000000..475892cdda --- /dev/null +++ b/docs/utils/index.ts @@ -0,0 +1,15 @@ +export const openUrl = ({ + href, + target, +}: { + href: string + target?: string +}) => { + switch (target) { + case '_blank': + window.open(href, target) + break + default: + window.location.href = href + } +}