Skip to content

Commit a49de81

Browse files
committed
Update meta tags and redirect handling for improved SPA support
1 parent cc05880 commit a49de81

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

index.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>browserstack-demo</title>
7-
<meta name="description" content="Browserstack Demo Project" />
7+
<meta name="description" content="Test Case Selection Demo Project" />
88
<meta name="author" content="cia-dev" />
99

10-
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
11-
<meta property="og:title" content="Browserstack Demo" />
12-
<meta property="og:description" content="Browserstack Demo Project" />
10+
<link rel="icon" type="image/svg+xml" href="./favicon.svg" />
11+
<meta property="og:title" content="Test Case Selection Demo" />
12+
<meta property="og:description" content="Test Case Selection Demo Project" />
1313
<meta property="og:type" content="website" />
14-
<meta property="og:image" content="/favicon.svg" />
14+
<meta property="og:image" content="./favicon.svg" />
1515

1616
<!-- GitHub Pages SPA redirect handling -->
1717
<script>
@@ -30,6 +30,6 @@
3030

3131
<body>
3232
<div id="root"></div>
33-
<script type="module" src="/src/main.tsx"></script>
33+
<script type="module" src="./src/main.tsx"></script>
3434
</body>
3535
</html>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "test-selection-demo-app-browserstack",
33
"version": "0.0.0",
44
"type": "module",
5-
"homepage": "https://browserstack.github.io/test-selection-demo-app-browserstack",
5+
"homepage": "https://browserstack.github.io/test-selection-demo-app-browserstack/",
66
"scripts": {
77
"predeploy": "npm run build",
88
"deploy": "gh-pages -d dist",

public/404.html

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>Loading...</title>
6+
<title>Redirecting...</title>
77
<script>
8-
// Surge serves 404.html for unknown routes unless a 200 fallback is provided.
9-
// Instead of mutating the URL (which produced /?/… redirects), load the main
10-
// SPA shell in-place so React Router can hydrate the correct route.
11-
fetch('/index.html', { credentials: 'same-origin' })
12-
.then((response) => response.text())
13-
.then((html) => {
14-
document.open();
15-
document.write(html);
16-
document.close();
17-
})
18-
.catch(() => {
19-
window.location.replace('/');
20-
});
8+
// SPA redirect for GitHub Pages: move path into query so index.html can restore it
9+
(function () {
10+
var l = window.location;
11+
// derive base path like /owner/repo or /repo depending on hosting
12+
var parts = l.pathname.split('/').filter(Boolean);
13+
// assume repo is the first path segment when hosted on browserstack.github.io
14+
var repoIndex = parts.indexOf('test-selection-demo-app-browserstack');
15+
var base = '/test-selection-demo-app-browserstack/';
16+
// If repo not found, fall back to root
17+
if (repoIndex === -1) {
18+
base = '/';
19+
}
20+
var newPath = base + '?/' + l.pathname.slice(base.length).replace(/&/g, '~and~') + (l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') + l.hash;
21+
l.replace(l.protocol + '//' + l.host + newPath);
22+
})();
2123
</script>
2224
</head>
2325
<body>
24-
<p>Loading the application…</p>
26+
<p>Redirecting to the app...</p>
2527
</body>
2628
</html>

public/_redirects

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const App = () => (
120120
<CartProvider>
121121
<QueryClientProvider client={queryClient}>
122122
<TooltipProvider>
123-
<BrowserRouter>
123+
<BrowserRouter basename={import.meta.env.BASE_URL}>
124124
<AppContent />
125125
</BrowserRouter>
126126
</TooltipProvider>

0 commit comments

Comments
 (0)