-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
67 lines (62 loc) · 2.75 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>NMDC Field Notes</title>
<base href="/" />
<meta name="theme-color" content="#00aae7" />
<meta name="color-scheme" content="light dark" />
<meta
name="viewport"
content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<link rel="manifest" href="/manifest.json" />
<link rel="shortcut icon" type="image/png" href="/favicon.png" />
<!-- add to homescreen for ios -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-title" content="NMDC Field Notes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
</head>
<body>
<div id="root"></div>
<script>
/**
* Retrieves the originally-requested URL, if any, from `sessionStorage` and—if that URL is both "valid and
* useful"—deletes that `sessionStorage` item and navigates to that URL on the client side.
*
* Note: In the context of this function, an originally-requested URL...
* - is "valid" if it has the same origin as the current URL
* - is "useful" if it differs from the current URL
*
* Note: We do this before the React app runs. The React app will only be aware of the "final" URL.
*
* References:
* - https://www.smashingmagazine.com/2016/08/sghpa-single-page-app-hack-github-pages/ (RE: the overall technique)
* - https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy#definition_of_an_origin
* - `404.html` (contains the script that stores the originally-requested URL in `sessionStorage`)
*/
(function navigateToOriginallyRequestedURL(
sessionStorage,
location,
history,
) {
const SESSION_STORAGE_KEY = "_originallyRequestedURLStr";
const originallyRequestedURLStr =
sessionStorage.getItem(SESSION_STORAGE_KEY);
if (originallyRequestedURLStr !== null) {
const originallyRequestedURL = new URL(originallyRequestedURLStr);
if (
originallyRequestedURL.origin === location.origin &&
originallyRequestedURL.href !== location.href
) {
sessionStorage.removeItem(SESSION_STORAGE_KEY); // we do this as late as possible to facilitate debugging
history.replaceState(null, null, originallyRequestedURL);
}
}
})(window.sessionStorage, window.location, window.history);
</script>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>