Skip to content

Commit

Permalink
Merge pull request #7 from JohnsonMao/develop
Browse files Browse the repository at this point in the history
feature: lazy import pages
  • Loading branch information
JohnsonMao authored Apr 7, 2024
2 parents 69ec54e + dc24c30 commit 532d701
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 25 deletions.
10 changes: 5 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VITE_CLIENT_ID=tutelary.maomao-5db761ff-e645-4b7f
VITE_CLIENT_SECRET=559eca3f-e101-4cfb-ad18-d7c779c84bfb
VITE_MAP_USERNAME=tutelarymao
VITE_MAP_STYLE_ID=ckwbtexnm49wp14p6ldeczyxv
VITE_MAP_TOKEN=pk.eyJ1IjoidHV0ZWxhcnltYW8iLCJhIjoiY2x1bnZxNDNyMWhsajJtbjI0dW9objd2diJ9.kGtX-QECwWyt6eXvb-vrrg
VITE_CLIENT_ID= # TDX Client ID
VITE_CLIENT_SECRET= # TDX Client Secret
VITE_MAP_USERNAME= # MapBox Username
VITE_MAP_STYLE_ID= # MapBox style ID
VITE_MAP_TOKEN= # MapBox token
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
},
"dependencies": {
"bootstrap": "5.1.3",
"jssha": "^3.2.0",
"leaflet": "^1.7.1",
"lottie-react-web": "^2.2.2",
"prop-types": "^15.7.2",
Expand Down
11 changes: 4 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 14 additions & 12 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import { HashRouter, Routes, Route, Navigate } from "react-router-dom";

import { Layout } from "./pages/Layout";
import Index from "./pages/Index";
import CityBus from "./pages/CityBus";
import Favorites from "./pages/Favorites";
import Nearby from "./pages/Nearby";
import SearchResult from "./components/SearchResult";
import RoutePage from "./components/RoutePage";
import withSuspense from "./components/withSuspense";
import "./asset/styles/style.scss";

const Index = withSuspense(() => import("./pages/Index"));
const CityBus = withSuspense(() => import("./pages/CityBus"));
const SearchResult = withSuspense(() => import("./components/SearchResult"));
const RoutePage = withSuspense(() => import("./components/RoutePage"));
const Nearby = withSuspense(() => import("./pages/Nearby"));
const Favorites = withSuspense(() => import("./pages/Favorites"));

export default function App() {
return (
<HashRouter>
<Routes>
<Route element={<Layout />}>
<Route index element={<Index />} />
<Route path="citybus" element={<CityBus />}>
<Route index element={<SearchResult />} />
<Route path=":id" element={<RoutePage />} />
<Route index element={Index} />
<Route path="citybus" element={CityBus}>
<Route index element={SearchResult} />
<Route path=":id" element={RoutePage} />
</Route>
<Route path="nearby/*" element={<Nearby />} />
<Route path="favorites" element={<Favorites />} />
<Route path="nearby/*" element={Nearby} />
<Route path="favorites" element={Favorites} />
<Route path="/*" element={<Navigate replace to="/" />} />
</Route>
</Routes>
Expand Down
13 changes: 13 additions & 0 deletions src/components/withSuspense.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Suspense, lazy } from "react";

export default function withSuspense(importer, loading = null) {
if (typeof importer !== "function") return null;

const LazyComponent = lazy(importer);

return (
<Suspense fallback={loading}>
<LazyComponent />
</Suspense>
);
}
3 changes: 3 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ export default defineConfig((config) =>({
},
],
},
server: {
port: 1473
}
}));

0 comments on commit 532d701

Please sign in to comment.