Skip to content

Commit bf1da7e

Browse files
committed
fix(website): update dependency react-router-dom to v6 #333
1 parent 9b20230 commit bf1da7e

File tree

15 files changed

+526
-549
lines changed

15 files changed

+526
-549
lines changed

website/.kktrc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default (conf: Configuration, env: 'development' | 'production', options:
1414
allowedFiles: [path.resolve(process.cwd(), 'README.md')],
1515
});
1616

17+
conf.module!.exprContextCritical = false;
1718
// Get the project version.
1819
conf.plugins!.push(
1920
new webpack.DefinePlugin({

website/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
},
1414
"license": "MIT",
1515
"dependencies": {
16-
"@rematch/core": "2.1.1",
17-
"@rematch/loading": "2.1.1",
18-
"@uiw/react-code-preview": "2.1.4",
16+
"@rematch/core": "2.2.0",
17+
"@rematch/loading": "2.1.2",
18+
"@uiw/react-code-preview": "2.2.2",
1919
"@uiw/react-markdown-preview": "3.4.1",
2020
"@uiw/react-native": "2.11.1",
2121
"@uiw/react-native-template": "2.2.2",
@@ -25,19 +25,19 @@
2525
"react-dynamic-loadable": "3.0.0",
2626
"react-native": "0.66.1",
2727
"react-native-web": "0.17.5",
28-
"react-redux": "7.2.5",
29-
"react-router-dom": "5.3.0",
28+
"react-redux": "7.2.6",
29+
"react-router-dom": "6.0.2",
3030
"rehype-rewrite": "3.0.4",
3131
"uiw": "4.7.16"
3232
},
3333
"devDependencies": {
3434
"@kkt/less-modules": "6.11.0",
3535
"@kkt/raw-modules": "6.11.0",
3636
"@kkt/scope-plugin-options": "6.11.0",
37-
"@types/react": "17.0.27",
38-
"@types/react-dom": "17.0.9",
39-
"@types/react-redux": "7.1.19",
40-
"@types/react-router-dom": "5.3.1",
37+
"@types/react": "17.0.34",
38+
"@types/react-dom": "17.0.11",
39+
"@types/react-redux": "7.1.20",
40+
"@types/react-router-dom": "5.3.2",
4141
"kkt": "6.11.0"
4242
},
4343
"eslintConfig": {

website/src/component/Container/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
import { Fragment } from 'react';
2+
import { Outlet, useLocation } from 'react-router-dom';
23
import Header from '../Header';
34
import SubMenus, { MenuData } from '../SubMenus';
45
import styles from './index.module.less';
6+
import { componentMenus, docsMenus } from '../../routes/menus';
57

68
interface ContainerProps extends React.HTMLAttributes<HTMLDivElement> {
79
data?: MenuData[];
810
path?: string;
911
}
1012

1113
export default function Container(props: ContainerProps) {
12-
const { data, children, path = '' } = props;
14+
const { path = '' } = props;
15+
const { pathname } = useLocation();
16+
let data: MenuData[] = [];
17+
if (/^\/components/.test(pathname)) {
18+
data = componentMenus;
19+
}
20+
if (/^\/docs/.test(pathname)) {
21+
data = docsMenus;
22+
}
1323
return (
1424
<Fragment>
1525
<Header enableStyle={/\/(team)/.test(path)} showBorder={/\/(home)/.test(path)} path={path} />
1626
<div className={styles.warpper}>
1727
{data && data.length > 0 && <SubMenus data={data} />}
1828
<div className={styles.content} style={{ flex: 1, overflow: 'hidden' }}>
19-
{children}
29+
<Outlet />
2030
</div>
2131
</div>
2232
</Fragment>
Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
import styles from './index.module.less';
22
import { useFetch } from '../../hook/useFetch';
3+
import { useState } from 'react';
4+
import { useMemo } from 'react';
35

46
type ContributorsProps = {
57
path?: string;
68
};
79

810
export default function Contributors(props: ContributorsProps) {
911
const { path } = props;
10-
if (!path) return null;
11-
let editPath = path;
12-
if (!/^(https?:\/\/)/.test(editPath)) {
13-
editPath = `https://github.com/uiwjs/react-native-uiw/edit/master/${path.replace(/^\//, '')}`;
14-
}
12+
const [editPath, setEditPath] = useState<string>();
13+
useMemo(() => {
14+
if (!path) return null;
15+
if (!/^(https?:\/\/)/.test(path)) {
16+
setEditPath(`https://github.com/uiwjs/react-native-uiw/edit/master/${path.replace(/^\//, '')}`);
17+
}
18+
}, [path]);
1519
return (
1620
<div className={styles.warpper}>
17-
<a className={styles.edit} href={editPath} target="__blank">
18-
<svg viewBox="0 0 1024 1024" width="14" height="14" fill="#757575">
19-
<path d="M837.818182 0H186.181818C134.981818 0 93.090909 41.890909 93.090909 93.090909v837.818182c0 51.2 41.890909 93.090909 93.090909 93.090909h651.636364c51.2 0 93.090909-41.890909 93.090909-93.090909V93.090909c0-51.2-41.890909-93.090909-93.090909-93.090909z m46.545454 912.290909c0 37.236364-27.927273 65.163636-65.163636 65.163636H204.8c-37.236364 0-65.163636-27.927273-65.163636-65.163636V111.709091C139.636364 74.472727 167.563636 46.545455 204.8 46.545455h614.4c37.236364 0 65.163636 27.927273 65.163636 65.163636v800.581818z" />
20-
<path d="M256 139.636364h418.909091c13.963636 0 23.272727 9.309091 23.272727 23.272727s-9.309091 23.272727-23.272727 23.272727h-418.909091c-13.963636 0-23.272727-9.309091-23.272727-23.272727s9.309091-23.272727 23.272727-23.272727zM256 279.272727h279.272727c13.963636 0 23.272727 9.309091 23.272728 23.272728s-9.309091 23.272727-23.272728 23.272727h-279.272727c-13.963636 0-23.272727-9.309091-23.272727-23.272727s9.309091-23.272727 23.272727-23.272728zM256 418.909091h139.636364c13.963636 0 23.272727 9.309091 23.272727 23.272727s-9.309091 23.272727-23.272727 23.272727h-139.636364c-13.963636 0-23.272727-9.309091-23.272727-23.272727s9.309091-23.272727 23.272727-23.272727z" />
21-
<path d="M256 581.818182m-23.272727 0a23.272727 23.272727 0 1 0 46.545454 0 23.272727 23.272727 0 1 0-46.545454 0Z" />
22-
<path d="M721.454545 558.545455h46.545455c13.963636 0 23.272727 9.309091 23.272727 23.272727s-9.309091 23.272727-23.272727 23.272727h-46.545455c-13.963636 0-23.272727-9.309091-23.272727-23.272727s9.309091-23.272727 23.272727-23.272727z" />
23-
<path d="M404.945455 768l-102.4-97.745455L781.963636 190.836364c27.927273-27.927273 69.818182-27.927273 97.745455 0s27.927273 69.818182 0 97.745454" />
24-
<path d="M339.781818 833.163636l-116.363636 18.618182 18.618182-116.363636 32.581818-32.581818L372.363636 800.581818" />
25-
</svg>
26-
在 GitHub 上编辑此页
27-
</a>
21+
{editPath && (
22+
<a className={styles.edit} href={editPath} target="__blank">
23+
<svg viewBox="0 0 1024 1024" width="14" height="14" fill="#757575">
24+
<path d="M837.818182 0H186.181818C134.981818 0 93.090909 41.890909 93.090909 93.090909v837.818182c0 51.2 41.890909 93.090909 93.090909 93.090909h651.636364c51.2 0 93.090909-41.890909 93.090909-93.090909V93.090909c0-51.2-41.890909-93.090909-93.090909-93.090909z m46.545454 912.290909c0 37.236364-27.927273 65.163636-65.163636 65.163636H204.8c-37.236364 0-65.163636-27.927273-65.163636-65.163636V111.709091C139.636364 74.472727 167.563636 46.545455 204.8 46.545455h614.4c37.236364 0 65.163636 27.927273 65.163636 65.163636v800.581818z" />
25+
<path d="M256 139.636364h418.909091c13.963636 0 23.272727 9.309091 23.272727 23.272727s-9.309091 23.272727-23.272727 23.272727h-418.909091c-13.963636 0-23.272727-9.309091-23.272727-23.272727s9.309091-23.272727 23.272727-23.272727zM256 279.272727h279.272727c13.963636 0 23.272727 9.309091 23.272728 23.272728s-9.309091 23.272727-23.272728 23.272727h-279.272727c-13.963636 0-23.272727-9.309091-23.272727-23.272727s9.309091-23.272727 23.272727-23.272728zM256 418.909091h139.636364c13.963636 0 23.272727 9.309091 23.272727 23.272727s-9.309091 23.272727-23.272727 23.272727h-139.636364c-13.963636 0-23.272727-9.309091-23.272727-23.272727s9.309091-23.272727 23.272727-23.272727z" />
26+
<path d="M256 581.818182m-23.272727 0a23.272727 23.272727 0 1 0 46.545454 0 23.272727 23.272727 0 1 0-46.545454 0Z" />
27+
<path d="M721.454545 558.545455h46.545455c13.963636 0 23.272727 9.309091 23.272727 23.272727s-9.309091 23.272727-23.272727 23.272727h-46.545455c-13.963636 0-23.272727-9.309091-23.272727-23.272727s9.309091-23.272727 23.272727-23.272727z" />
28+
<path d="M404.945455 768l-102.4-97.745455L781.963636 190.836364c27.927273-27.927273 69.818182-27.927273 97.745455 0s27.927273 69.818182 0 97.745454" />
29+
<path d="M339.781818 833.163636l-116.363636 18.618182 18.618182-116.363636 32.581818-32.581818L372.363636 800.581818" />
30+
</svg>
31+
在 GitHub 上编辑此页
32+
</a>
33+
)}
2834
<AvatarList path={path} />
2935
</div>
3036
);
@@ -35,25 +41,25 @@ type Response = Array<{
3541
url: string;
3642
}>;
3743

38-
function AvatarList(props: { path: string }) {
39-
const { path } = props;
44+
function AvatarList(props: { path?: string }) {
45+
const { path = '' } = props;
4046
const fetchurl = `https://proapi.azurewebsites.net/doc/getAvatarList?filename=${path.replace(
4147
/^\//,
4248
'',
4349
)}&owner=uiwjs&repo=react-native-uiw`;
4450
const res = useFetch<Response>(fetchurl);
45-
if (!res.response) {
46-
return <span className={styles.avatar} />;
51+
if (res.response) {
52+
return (
53+
<span className={styles.avatar}>
54+
{res.response.map((item, idx) => {
55+
return (
56+
<a href={`https://github.com/${item.username}`} key={idx} target="__blank">
57+
<img src={item.url} alt={item.username} />
58+
</a>
59+
);
60+
})}
61+
</span>
62+
);
4763
}
48-
return (
49-
<span className={styles.avatar}>
50-
{res.response.map((item, idx) => {
51-
return (
52-
<a href={`https://github.com/${item.username}`} key={idx} target="__blank">
53-
<img src={item.url} alt={item.username} />
54-
</a>
55-
);
56-
})}
57-
</span>
58-
);
64+
return <span className={styles.avatar} />;
5965
}

website/src/component/Header/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ interface HeaderProps extends React.HTMLAttributes<HTMLElement> {
1414
export default function Header(props: HeaderProps) {
1515
const { showBorder = true, enableStyle, style = {} } = props;
1616
// @ts-ignore
17-
// eslint-disable-next-line
1817
const version = pkg.version || '2.0.0';
1918

2019
if (showBorder || enableStyle) {
@@ -36,8 +35,8 @@ export default function Header(props: HeaderProps) {
3635
</Link>
3736
<div className={styles.menus}>
3837
<NavLink to="/home">首页</NavLink>
39-
<NavLink to="/docs/">文档</NavLink>
40-
<NavLink to="/components/">RN组件</NavLink>
38+
<NavLink to="/docs">文档</NavLink>
39+
<NavLink to="/components">RN组件</NavLink>
4140
<a target="__blank" href="https://github.com/uiwjs/react-native-uiw/issues">
4241
问题反馈
4342
</a>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Fragment } from 'react';
2+
import Footer from '../../component/Footer';
3+
4+
export default function NotFound() {
5+
return (
6+
<Fragment>
7+
<div
8+
style={{
9+
minHeight: 230,
10+
fontSize: 28,
11+
fontWeight: 'bold',
12+
color: '#c1c1c1',
13+
display: 'flex',
14+
alignItems: 'center',
15+
justifyContent: 'center',
16+
}}
17+
>
18+
Not Found
19+
</div>
20+
<Footer />
21+
</Fragment>
22+
);
23+
}

website/src/hook/useFetch.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
1-
import React from 'react';
1+
import { useState, useEffect } from 'react';
22

33
type UseFetchResult<F> = {
44
error?: any;
55
response?: F | null;
66
};
77

88
export function useFetch<T>(url: string, options?: RequestInit): UseFetchResult<T> {
9-
const [response, setResponse] = React.useState(null);
10-
const [error, setError] = React.useState(null);
9+
const [response, setResponse] = useState(null);
10+
const [error, setError] = useState<unknown>(null);
1111

12-
React.useEffect(() => {
12+
useEffect(() => {
13+
let mounted = true;
1314
const fetchData = async () => {
1415
try {
1516
const res = await fetch(url, options);
1617
const json = await res.json();
17-
setResponse(json);
18+
if (mounted) {
19+
setResponse(json);
20+
}
1821
} catch (error) {
19-
setError(error);
22+
if (mounted) {
23+
setError(error);
24+
}
2025
}
2126
};
2227
fetchData();
28+
return () => {
29+
mounted = false;
30+
};
2331
// eslint-disable-next-line react-hooks/exhaustive-deps
2432
}, []);
2533

website/src/index.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import { HashRouter as Router, withRouter, RouteComponentProps } from 'react-router-dom';
3+
import { HashRouter } from 'react-router-dom';
44
import { Provider } from 'react-redux';
55
import '@uiw/reset.css';
6-
import './index.css';
76
import { store } from './models';
87
import Controller from './routes/Controller';
9-
import { getRouterData } from './routes/router';
10-
11-
export type DefaultProps = React.PropsWithChildren<RouteComponentProps<any>> & {
12-
routerData: typeof getRouterData;
13-
};
8+
import './index.css';
149

15-
const Container = withRouter((props) => {
16-
const routerData = getRouterData;
17-
const resetProps: DefaultProps = { ...props, routerData };
18-
return <Controller {...resetProps} />;
19-
});
10+
export type DefaultProps = React.PropsWithChildren<any> & {};
2011

2112
ReactDOM.render(
2213
<Provider store={store}>
23-
<Router>
24-
<Container />
25-
</Router>
14+
<HashRouter>
15+
<Controller />
16+
</HashRouter>
2617
</Provider>,
2718
document.getElementById('root'),
2819
);

website/src/layouts/BasicLayout.module.less

Whitespace-only changes.

website/src/layouts/BasicLayout.tsx

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)