Skip to content

Commit 5efd0e5

Browse files
committed
u6
1 parent 0da7d7d commit 5efd0e5

4 files changed

Lines changed: 34 additions & 49 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"web-vitals": "^2.1.4"
1515
},
1616
"scripts": {
17-
"predeploy": "npm run build",
18-
"deploy": "touch build/.nojekyll && gh-pages -d build --dotfiles",
17+
"predeploy": "npm run build && cp public/CNAME build/ && touch build/.nojekyll",
18+
"deploy": "gh-pages -d build --dotfiles",
1919
"start": "react-scripts start",
2020
"build": "react-scripts build",
2121
"test": "react-scripts test",

public/404.html

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,21 @@
77
// Single Page Apps for GitHub Pages
88
// MIT License
99
// https://github.com/rafgraph/spa-github-pages
10-
// This script takes the current url and converts the path and query
11-
// string into just a query string, and then redirects the browser
12-
// to the new url with only a query string and hash fragment
13-
14-
// If you're creating a Project Pages site and NOT using a custom domain,
15-
// then set pathSegmentsToKeep to 1 (enterprise users may need to set it to > 1).
16-
// This way the code will only replace the route part of the path, and not
17-
// the real directory in which the app resides, for example:
18-
// https://username.github.io/repo-name/one/two?a=b&c=d#qwe becomes
19-
// https://username.github.io/repo-name/?/one/two&a=b~and~c=d#qwe
20-
// Otherwise, leave pathSegmentsToKeep as 0.
21-
var pathSegmentsToKeep = 0;
22-
23-
var l = window.location;
24-
l.replace(
25-
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
26-
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' +
27-
l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') +
28-
(l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') +
29-
l.hash
30-
);
10+
11+
// This script will redirect all paths to the root index.html
12+
// which is especially important for a React app with React Router
13+
14+
// Redirect to the root page while preserving the path in the URL
15+
window.location.href =
16+
window.location.protocol + '//' +
17+
window.location.hostname +
18+
(window.location.port ? ':' + window.location.port : '') +
19+
'/' +
20+
window.location.pathname.split('/').slice(1).join('/');
3121
</script>
3222
</head>
3323
<body>
24+
<h1>Redirecting...</h1>
25+
<p>If you are not redirected automatically, <a href="/">click here</a>.</p>
3426
</body>
3527
</html>

public/index.html

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<meta name="theme-color" content="#000000" />
88
<meta
99
name="description"
10-
content="Web site created using create-react-app"
10+
content="UPenn EcoVenture Challenge - Environmental startup pitch competition"
1111
/>
1212
<link rel="apple-touch-icon" href="%PUBLIC_URL%/apple-touch-icon.png" />
1313
<!--
@@ -25,30 +25,24 @@
2525
Learn how to configure a non-root public URL by running `npm run build`.
2626
-->
2727
<title>UPenn EcoVenture Challenge</title>
28-
<!-- Start Single Page Apps for GitHub Pages -->
28+
<!-- Simplified script to handle routing for SPA -->
2929
<script type="text/javascript">
30-
// Single Page Apps for GitHub Pages
31-
// MIT License
32-
// https://github.com/rafgraph/spa-github-pages
33-
// This script checks to see if a redirect is present in the query string,
34-
// converts it back into the correct url and adds it to the
35-
// browser's history using window.history.replaceState(...),
36-
// which won't cause the browser to attempt to load the new url.
37-
// When the single page app is loaded further down in this file,
38-
// the correct url will be waiting in the browser's history for
39-
// the single page app to route accordingly.
40-
(function(l) {
41-
if (l.search[1] === '/' ) {
42-
var decoded = l.search.slice(1).split('&').map(function(s) {
43-
return s.replace(/~and~/g, '&')
44-
}).join('?');
45-
window.history.replaceState(null, null,
46-
l.pathname.slice(0, -1) + decoded + l.hash
47-
);
30+
// This is a simplified approach to handle routes on a custom domain
31+
// No complex path manipulation required when using a custom domain
32+
33+
// If coming from a redirect with a specific path, this will
34+
// ensure the React Router handles it correctly
35+
if (window.location.search) {
36+
try {
37+
const path = window.location.search.substring(1);
38+
if (path) {
39+
window.history.replaceState(null, null, '/' + path);
40+
}
41+
} catch (e) {
42+
console.error('Error handling redirect:', e);
4843
}
49-
}(window.location))
44+
}
5045
</script>
51-
<!-- End Single Page Apps for GitHub Pages -->
5246
</head>
5347
<body>
5448
<noscript>You need to enable JavaScript to run this app.</noscript>

src/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import App from './App';
55
import reportWebVitals from './reportWebVitals';
66
import { BrowserRouter } from 'react-router-dom';
77

8-
// Dynamically set basename based on the hostname
9-
// No basename needed for custom domain, but use /prize-website-v2 for github.io
10-
const isGitHubPages = window.location.hostname.includes('github.io');
11-
const basename = isGitHubPages ? '/prize-website-v2' : '/';
8+
// For a custom domain, we should always use '/' as the basename
9+
// The only time we need a different basename is for GitHub Pages without a custom domain
10+
const basename = '/';
1211

1312
const root = ReactDOM.createRoot(document.getElementById('root'));
1413
root.render(

0 commit comments

Comments
 (0)