Skip to content

Commit d898b70

Browse files
committed
refactor(platform): add AppRoute to generate page
1 parent a6f9609 commit d898b70

11 files changed

Lines changed: 39 additions & 18 deletions

File tree

packages/platform/src/app/Routes.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export const AppRoutes = React.memo(() => {
269269
title,
270270
}}
271271
>
272-
<React.Fragment key={location.pathname}>{element}</React.Fragment>
272+
{element}
273273
</RouteStateContext.Provider>
274274
);
275275
});

packages/platform/src/app/routes/dashboard/amap/AMap.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { useImmer } from '@react-devui/hooks';
44
import { DRadio } from '@react-devui/ui';
55

66
import { AppMap } from '../../../components';
7+
import { AppRoute } from '../../../utils';
78
import styles from './AMap.module.scss';
89
import points from './points';
910

10-
export default function AMap(): JSX.Element | null {
11+
export default AppRoute(() => {
1112
const [mapTmp, setMapTmp] = useState('Marker');
1213
const [infoWindow, setInfoWindow] = useImmer<{ visible: boolean; position?: [number, number] }>({ visible: false });
1314

@@ -65,4 +66,4 @@ export default function AMap(): JSX.Element | null {
6566
</AppMap>
6667
</div>
6768
);
68-
}
69+
});

packages/platform/src/app/routes/dashboard/echarts/ECharts.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import { useMount } from '@react-devui/hooks';
55
import { DCard } from '@react-devui/ui';
66

77
import { AppChart, AppRouteHeader } from '../../../components';
8+
import { AppRoute } from '../../../utils';
89
import styles from './ECharts.module.scss';
910
import { barOptions, lineOptions, nightingaleOptions, pieOptions, scatterOptions, stackedBarOptions, stackedLineOptions } from './options';
1011

11-
export default function ECharts(): JSX.Element | null {
12+
export default AppRoute(() => {
1213
const [options, setOptions] = useState<echarts.EChartsOption[]>([]);
1314
const { t } = useTranslation();
1415

@@ -42,4 +43,4 @@ export default function ECharts(): JSX.Element | null {
4243
</div>
4344
</>
4445
);
45-
}
46+
});

packages/platform/src/app/routes/exception/Exception.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import { useNavigate, useParams } from 'react-router-dom';
44

55
import { DButton } from '@react-devui/ui';
66

7+
import { AppRoute } from '../../utils';
78
import { ReactComponent as S403 } from './403.svg';
89
import { ReactComponent as S404 } from './404.svg';
910
import { ReactComponent as S500 } from './500.svg';
1011
import styles from './Exception.module.scss';
1112

12-
export default function Exception(): JSX.Element | null {
13+
export default AppRoute(() => {
1314
const { t } = useTranslation();
1415
const navigate = useNavigate();
1516

@@ -31,4 +32,4 @@ export default function Exception(): JSX.Element | null {
3132
</div>
3233
</div>
3334
);
34-
}
35+
});

packages/platform/src/app/routes/list/standard-table/StandardTable.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { DButton, DCard, DCheckbox, DDropdown, DModal, DPagination, DSelect, DSe
1212

1313
import { AppRouteHeader, AppStatusDot, AppTableFilter } from '../../../components';
1414
import { useAPI, useQueryParams } from '../../../hooks';
15+
import { AppRoute } from '../../../utils';
1516
import { AppDeviceModal } from './DeviceModal';
1617
import styles from './StandardTable.module.scss';
1718

@@ -26,7 +27,7 @@ interface DeviceQueryParams {
2627
pageSize: number;
2728
}
2829

29-
export default function StandardTable(): JSX.Element | null {
30+
export default AppRoute(() => {
3031
const deviceModalRef = useRef<OpenSettingFn<DeviceData>>(null);
3132

3233
const { t } = useTranslation();
@@ -390,4 +391,4 @@ export default function StandardTable(): JSX.Element | null {
390391
</div>
391392
</>
392393
);
393-
}
394+
});

packages/platform/src/app/routes/list/standard-table/detail/Detail.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import { DButton, DCard, DSeparator, DSpinner, DTable } from '@react-devui/ui';
1111

1212
import { AppDetailView, AppRouteHeader } from '../../../../components';
1313
import { useAPI } from '../../../../hooks';
14+
import { AppRoute } from '../../../../utils';
1415
import { AppDeviceModal } from '../DeviceModal';
1516
import styles from './Detail.module.scss';
1617

17-
export default function Detail(): JSX.Element | null {
18+
export default AppRoute(() => {
1819
const deviceModalRef = useRef<OpenSettingFn<DeviceData>>(null);
1920

2021
const { t } = useTranslation();
@@ -135,4 +136,4 @@ export default function Detail(): JSX.Element | null {
135136
</div>
136137
</>
137138
);
138-
}
139+
});

packages/platform/src/app/routes/login/Login.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import { AppLanguage } from '../../components';
1515
import { LOGIN_PATH } from '../../config/other';
1616
import { APP_NAME } from '../../config/other';
1717
import { TOKEN, useHttp, useInit } from '../../core';
18-
import { NotificationService } from '../../utils';
18+
import { AppRoute, NotificationService } from '../../utils';
1919
import styles from './Login.module.scss';
2020
import { BASE64_DATA } from './base64.out';
2121

22-
export default function Login(): JSX.Element | null {
22+
export default AppRoute(() => {
2323
const { t } = useTranslation();
2424
const http = useHttp();
2525
const [loginloading, setLoginLoading] = useState(false);
@@ -207,4 +207,4 @@ export default function Login(): JSX.Element | null {
207207
</footer>
208208
</div>
209209
);
210-
}
210+
});

packages/platform/src/app/routes/test/acl/ACL.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import { DAlert, DButton, DCard, DTable, DTag } from '@react-devui/ui';
66

77
import { AppRouteHeader } from '../../../components';
88
import { useACL } from '../../../core';
9+
import { AppRoute } from '../../../utils';
910
import styles from './ACL.module.scss';
1011

11-
export default function ACL(): JSX.Element | null {
12+
export default AppRoute(() => {
1213
const acl = useACL();
1314
const { t } = useTranslation();
1415
const navigate = useNavigate();
@@ -68,4 +69,4 @@ export default function ACL(): JSX.Element | null {
6869
</div>
6970
</>
7071
);
71-
}
72+
});

packages/platform/src/app/routes/test/http/Http.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { DButton, DCard } from '@react-devui/ui';
44

55
import { AppRouteHeader } from '../../../components';
66
import { useHttp } from '../../../core';
7+
import { AppRoute } from '../../../utils';
78
import styles from './Http.module.scss';
89

9-
export default function Http(): JSX.Element | null {
10+
export default AppRoute(() => {
1011
const http = useHttp();
1112
const { t } = useTranslation();
1213

@@ -45,4 +46,4 @@ export default function Http(): JSX.Element | null {
4546
</div>
4647
</>
4748
);
48-
}
49+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* eslint-disable react-hooks/rules-of-hooks */
2+
import React from 'react';
3+
import { useLocation } from 'react-router-dom';
4+
5+
export function AppRoute(FC: React.FC) {
6+
return (props: { aReloadWhenPathChange?: boolean }) => {
7+
const { aReloadWhenPathChange = true } = props;
8+
9+
const location = useLocation();
10+
11+
return React.createElement(FC, aReloadWhenPathChange ? { key: location.pathname } : undefined);
12+
};
13+
}

0 commit comments

Comments
 (0)