Skip to content

Commit 0fd1d50

Browse files
Feat: Update React app Routing strategy (#153)
* configure react app basename for server builds * chore: prettier * update server comment * run prettier again * leverage hash router for client side routing * remove basename prop * update anchor copy * chore: prettier
1 parent 287c530 commit 0fd1d50

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

client/index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,7 @@ <h2>Dynamic Examples</h2>
256256
Prebuilt Pages (React)
257257
<ul>
258258
<li>
259-
<a href="/client/prebuiltPages/react/oneTimePayment/dist/index.html"
260-
>One-Time Payment (React)</a
261-
>
259+
<a href="/client/prebuiltPages/react/dist/">React Demos</a>
262260
</li>
263261
</ul>
264262
</li>

client/prebuiltPages/react/src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useState } from "react";
2-
import { BrowserRouter, Routes, Route, Link } from "react-router-dom";
2+
import { Routes, Route, Link, HashRouter } from "react-router-dom";
33
import { PayPalProvider } from "@paypal/react-paypal-js/sdk-v6";
44
import { ErrorBoundary, useErrorBoundary } from "react-error-boundary";
55

@@ -98,7 +98,7 @@ function App() {
9898
]}
9999
pageType="checkout"
100100
>
101-
<BrowserRouter>
101+
<HashRouter>
102102
<Navigation />
103103
<Routes>
104104
{/* Home page */}
@@ -176,7 +176,7 @@ function App() {
176176
element={<ErrorBoundaryTestPage />}
177177
/>
178178
</Routes>
179-
</BrowserRouter>
179+
</HashRouter>
180180
</PayPalProvider>
181181
</ErrorBoundary>
182182
);

client/prebuiltPages/react/vite.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { defineConfig } from "vite";
22
import react from "@vitejs/plugin-react";
33

44
// https://vite.dev/config/
5-
export default defineConfig({
5+
export default defineConfig(({ command }) => ({
66
plugins: [react()],
7-
base: "./",
7+
base: command === "build" ? "/client/prebuiltPages/react/dist" : "./",
88
server: {
99
port: 3000,
1010
proxy: {
@@ -15,4 +15,4 @@ export default defineConfig({
1515
},
1616
},
1717
},
18-
});
18+
}));

0 commit comments

Comments
 (0)