Browse Source

docs: Auto redirect v3 link (#21875)

* redirect link

* add ignore
pull/21880/head
二货机器人 5 years ago
committed by GitHub
parent
commit
faa3eb3535
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .eslintignore
  2. 1
      .gitignore
  3. 24
      site/theme/template/NotFound.jsx
  4. 61
      site/theme/template/NotFound.tsx

1
.eslintignore

@ -16,6 +16,7 @@ site/theme/template/Content/Article.jsx
site/theme/template/Content/EditButton.jsx
site/theme/template/Resources/*.jsx
site/theme/template/Resources/**/*.jsx
site/theme/template/NotFound.jsx
typings
es/**/*
lib/**/*

1
.gitignore

@ -54,3 +54,4 @@ site/theme/template/Content/Article.jsx
site/theme/template/Content/EditButton.jsx
site/theme/template/Resources/*.jsx
site/theme/template/Resources/**/*.jsx
site/theme/template/NotFound.jsx

24
site/theme/template/NotFound.jsx

@ -1,24 +0,0 @@
import React from 'react';
import { Link } from 'bisheng/router';
import * as utils from './utils';
export default function NotFound({ location }) {
return (
<div id="page-404">
<section>
<h1>404</h1>
<p>
你要找的页面不存在
<Link to={utils.getLocalizedPathname('/', utils.isZhCN(location.pathname))}>
返回首页
</Link>
</p>
</section>
<style
dangerouslySetInnerHTML={{
__html: '#react-content { height: 100%; background-color: #fff }',
}}
/>
</div>
);
}

61
site/theme/template/NotFound.tsx

@ -0,0 +1,61 @@
import React from 'react';
import { Link } from 'bisheng/router';
import * as utils from './utils';
export interface NotFoundProps {
location: {
pathname: string;
search: string;
hash: string;
state: any;
action: string;
key: any;
basename: string;
query: Record<string, string>;
};
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',
};
export default function NotFound(props: NotFoundProps) {
const {
location: { pathname },
router,
} = props;
React.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]}`, utils.isZhCN(pathname)),
);
}
}
}, []);
return (
<div id="page-404">
<section>
<h1>404!</h1>
<p>
<Link to={utils.getLocalizedPathname('/', utils.isZhCN(pathname))}></Link>
</p>
</section>
<style
dangerouslySetInnerHTML={{
__html: '#react-content { height: 100%; background-color: #fff }',
}}
/>
</div>
);
}
Loading…
Cancel
Save