Skip to content

Commit 74fecf3

Browse files
committed
fix: github pages base url
1 parent a7d0044 commit 74fecf3

4 files changed

Lines changed: 67 additions & 1 deletion

File tree

index.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@
6868
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap"
6969
/>
7070
</noscript>
71+
<!-- SPA GitHub Pages Redirect Decoder -->
72+
<script type="text/javascript">
73+
(function (l) {
74+
if (l.search[1] === "/") {
75+
var decoded = l.search
76+
.slice(1)
77+
.split("&")
78+
.map(function (s) {
79+
return s.replace(/~and~/g, "&");
80+
})
81+
.join("?");
82+
window.history.replaceState(
83+
null,
84+
null,
85+
l.pathname.slice(0, -1) + decoded + l.hash,
86+
);
87+
}
88+
})(window.location);
89+
</script>
7190
<title>ArX Finote — Catatan Keuangan Pribadi</title>
7291
</head>
7392
<body

public/404.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<script>
77
// Single Page Apps for GitHub Pages SPA redirect
88
// https://github.com/rafgraph/spa-github-pages
9-
var pathSegmentsToKeep = 0;
9+
var pathSegmentsToKeep = window.location.hostname.endsWith(".github.io") ? 1 : 0;
1010
var l = window.location;
1111
l.replace(
1212
l.protocol +

src/app.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export function App() {
1616
<LocationProvider>
1717
<Router>
1818
<Route path="/" component={Layout} />
19+
<Route path="/arxfinote" component={Layout} />
20+
<Route path="/index.html" component={Layout} />
21+
<Route path="/arxfinote/index.html" component={Layout} />
1922
<Route default component={NotFound} />
2023
</Router>
2124
</LocationProvider>

src/app.test.jsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
2+
import { render, screen, waitFor } from "@testing-library/preact";
3+
import { App } from "./app";
4+
5+
describe("App Routing", () => {
6+
beforeEach(() => {
7+
// Reset path before each test
8+
window.history.replaceState(null, "", "/");
9+
});
10+
11+
afterEach(() => {
12+
window.history.replaceState(null, "", "/");
13+
});
14+
15+
it("renders Layout at root path '/'", async () => {
16+
window.history.replaceState(null, "", "/");
17+
render(<App />);
18+
19+
await waitFor(() => {
20+
expect(screen.getByText("Finote")).toBeInTheDocument();
21+
});
22+
expect(screen.queryByText("Halaman Tidak Ditemukan")).not.toBeInTheDocument();
23+
});
24+
25+
it("renders Layout at GitHub Pages repository path '/arxfinote'", async () => {
26+
window.history.replaceState(null, "", "/arxfinote");
27+
render(<App />);
28+
29+
await waitFor(() => {
30+
expect(screen.getByText("Finote")).toBeInTheDocument();
31+
});
32+
expect(screen.queryByText("Halaman Tidak Ditemukan")).not.toBeInTheDocument();
33+
});
34+
35+
it("renders NotFound page for unknown routes", async () => {
36+
window.history.replaceState(null, "", "/halaman-ngawur");
37+
render(<App />);
38+
39+
await waitFor(() => {
40+
expect(screen.getByText("Halaman Tidak Ditemukan")).toBeInTheDocument();
41+
});
42+
expect(screen.getByText("404")).toBeInTheDocument();
43+
});
44+
});

0 commit comments

Comments
 (0)