forked from ubiquity/uusd.ubq.fi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.ts
33 lines (28 loc) · 766 Bytes
/
router.ts
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
import { loadHomePage } from "./pages/home";
import { loadMintPage } from "./pages/mint";
import { loadRedeemPage } from "./pages/redeem";
// URL Path based routing
export async function handleRouting() {
const contentArea = document.getElementById("content-area");
if (!contentArea) return;
switch (window.location.hash) {
case "#/mint":
await loadMintPage();
break;
case "#/redeem":
await loadRedeemPage();
break;
case "":
case "#/":
case "#/index.html":
await loadHomePage();
break;
default:
// Redirect to home if no route matches
window.location.hash = "#/";
break;
}
}
// Run handleRouting on hashchange
window.addEventListener("hashchange", handleRouting);
export {};