2020-03-24 12:33:01 +08:00
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import { Result, Button } from 'antd';
|
|
|
|
import { HomeOutlined } from '@ant-design/icons';
|
2022-11-09 12:28:04 +08:00
|
|
|
import { Link, useLocation } from 'dumi';
|
|
|
|
import * as utils from '../../theme/utils';
|
2020-03-04 22:35:18 +08:00
|
|
|
|
|
|
|
export interface NotFoundProps {
|
|
|
|
router: {
|
|
|
|
push: (pathname: string) => void;
|
|
|
|
replace: (pathname: string) => void;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const DIRECT_MAP: Record<string, string> = {
|
|
|
|
'docs/spec/download': 'docs/resources',
|
|
|
|
'docs/spec/work-with-us': 'docs/resources',
|
|
|
|
};
|
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
const NotFoundPage: React.FC<NotFoundProps> = ({ router }) => {
|
|
|
|
const { pathname } = useLocation();
|
2020-03-04 22:35:18 +08:00
|
|
|
|
2020-03-24 12:33:01 +08:00
|
|
|
const isZhCN = utils.isZhCN(pathname);
|
|
|
|
|
|
|
|
useEffect(() => {
|
2020-03-04 22:35:18 +08:00
|
|
|
const directLinks = Object.keys(DIRECT_MAP);
|
|
|
|
for (let i = 0; i < directLinks.length; i += 1) {
|
|
|
|
const matchPath = directLinks[i];
|
|
|
|
if (pathname.includes(matchPath)) {
|
2020-09-14 10:48:08 +08:00
|
|
|
router.replace(utils.getLocalizedPathname(`/${DIRECT_MAP[matchPath]}`, isZhCN).pathname);
|
2020-03-04 22:35:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div id="page-404">
|
|
|
|
<section>
|
2020-03-24 12:33:01 +08:00
|
|
|
<Result
|
|
|
|
status="404"
|
|
|
|
title="404"
|
|
|
|
subTitle={
|
|
|
|
isZhCN ? '你访问的页面貌似不存在?' : 'Sorry, the page you visited does not exist.'
|
|
|
|
}
|
|
|
|
extra={
|
|
|
|
<Link to={utils.getLocalizedPathname('/', isZhCN)}>
|
|
|
|
<Button type="primary" icon={<HomeOutlined />}>
|
|
|
|
{isZhCN ? '返回 Ant Design 首页' : 'Back to home page'}
|
|
|
|
</Button>
|
|
|
|
</Link>
|
|
|
|
}
|
|
|
|
/>
|
2020-03-04 22:35:18 +08:00
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
);
|
2022-11-09 12:28:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default NotFoundPage;
|