App.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import "@/assets/styles/base.css";
  2. import React from "react";
  3. import SpinLoding from "./components/SpinLoding";
  4. import AsyncSpinLoding from "./components/AsyncSpinLoding";
  5. import { Router, Route, Switch } from "react-router-dom";
  6. import { Image } from "antd";
  7. import history from "./utils/history";
  8. import { useSelector } from "react-redux";
  9. import store, { RootState } from "./store";
  10. import MessageCom from "./components/Message";
  11. // 使用 React.lazy 懒加载页面
  12. const A1Home = React.lazy(() => import("./pages/A1Home"));
  13. const A2Main = React.lazy(() => import("./pages/A2Main"));
  14. const A3Goods = React.lazy(() => import("./pages/A3Goods"));
  15. const NotFound = React.lazy(() => import("@/components/NotFound"));
  16. function App() {
  17. // 从仓库中获取查看图片的信息
  18. const lookBigImg = useSelector(
  19. (state: RootState) => state.A0layout.lookBigImg
  20. );
  21. return (
  22. <div id="app">
  23. {/* 关于路由 */}
  24. <Router history={history}>
  25. <React.Suspense fallback={<SpinLoding />}>
  26. <Switch>
  27. {/* 封面页 */}
  28. <Route path="/" exact component={A1Home} />
  29. {/* 主要页 */}
  30. <Route path="/main" exact component={A2Main} />
  31. {/* 通过文物分享id打开的页面 */}
  32. <Route path="/goods" component={A3Goods} />
  33. {/* 找不到页面 */}
  34. <Route path="*" component={NotFound} />
  35. </Switch>
  36. </React.Suspense>
  37. </Router>
  38. {/* 发送请求的加载组件 */}
  39. <AsyncSpinLoding />
  40. {/* 所有图片点击预览查看大图 */}
  41. <Image
  42. preview={{
  43. visible: lookBigImg.show,
  44. src: lookBigImg.url,
  45. onVisibleChange: (value) => {
  46. // 清除仓库信息
  47. store.dispatch({
  48. type: "layout/lookBigImg",
  49. payload: { url: "", show: false },
  50. });
  51. },
  52. }}
  53. />
  54. {/* antd 轻提示 ---兼容360浏览器 */}
  55. <MessageCom />
  56. </div>
  57. );
  58. }
  59. const MemoApp = React.memo(App);
  60. export default MemoApp;