ant-design/.dumi/pages/404/index.tsx
二货爱吃白萝卜 7276438486
docs: Report 404 for monitor (#40278)
* docs: monitor 404 report

* docs: Add source

* docs: patch

* docs: clean up
2023-01-17 14:27:14 +08:00

66 lines
1.8 KiB
TypeScript

import { HomeOutlined } from '@ant-design/icons';
import { Button, Result } from 'antd';
import { Link, useLocation } from 'dumi';
import React, { useEffect } from 'react';
import * as utils from '../../theme/utils';
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',
};
const NotFoundPage: React.FC<NotFoundProps> = ({ router }) => {
const { pathname } = useLocation();
const isZhCN = utils.isZhCN(pathname);
useEffect(() => {
const directLinks = Object.keys(DIRECT_MAP);
for (let i = 0; i < directLinks.length; i += 1) {
const matchPath = directLinks[i];
if (pathname.includes(matchPath)) {
router.replace(utils.getLocalizedPathname(`/${DIRECT_MAP[matchPath]}`, isZhCN).pathname);
}
}
// Report if necessary
const { yuyanMonitor } = window as any;
if (yuyanMonitor) {
yuyanMonitor.log({
code: 11,
msg: `Page not found: ${location.href}; Source: ${document.referrer}`,
});
}
}, []);
return (
<div id="page-404">
<section>
<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>
}
/>
</section>
</div>
);
};
export default NotFoundPage;