Fix base route navigation

This commit is contained in:
KingRainbow44 2023-04-10 01:16:53 -04:00
parent 5ac93645e4
commit 18c143e12f
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
3 changed files with 8 additions and 4 deletions

View File

@ -1,5 +1,7 @@
import { EventEmitter } from "events"; import { EventEmitter } from "events";
import type { Page } from "@backend/types"; import type { Page } from "@backend/types";
import { isPage } from "@backend/types";
const emitter = new EventEmitter(); const emitter = new EventEmitter();
const navigation = new EventEmitter(); const navigation = new EventEmitter();
@ -18,14 +20,14 @@ export function setup(): void {
setTimeout(() => { setTimeout(() => {
// Check if the window's href is a page. // Check if the window's href is a page.
const page = window.location.href.split("/").pop(); const page = window.location.href.split("/").pop();
if (page == undefined) return; if (page == undefined || page == "") return;
// Convert the page to a Page type. // Convert the page to a Page type.
const pageName = page.charAt(0).toUpperCase() + page.slice(1); const pageName = page.charAt(0).toUpperCase() + page.slice(1);
const pageType = pageName as Page; const pageType = pageName as Page;
// Navigate to the page. // Navigate to the page.
navigate(pageType, false); isPage(page) && navigate(pageType, false);
}, 3e2); }, 3e2);
} }

View File

@ -124,7 +124,7 @@ export enum ItemCategory {
* @param page The string to check. * @param page The string to check.
*/ */
export function isPage(page: string): page is Page { export function isPage(page: string): page is Page {
return ["Home", "Commands"].includes(page); return ["Home", "Commands", "Avatars", "Items", "Entities", "Scenes"].includes(page);
} }
/** /**

View File

@ -23,7 +23,9 @@ class App extends React.Component<{}, IState> {
// Check if the window's href is a page. // Check if the window's href is a page.
let targetPage = null; let targetPage = null;
const page = window.location.href.split("/").pop(); const page = window.location.href.split("/").pop();
if (page != undefined) { console.log(page)
if (page != undefined && page != "") {
// Convert the page to a Page type. // Convert the page to a Page type.
const pageName = page.charAt(0).toUpperCase() + page.slice(1); const pageName = page.charAt(0).toUpperCase() + page.slice(1);
// Check if the page is a valid page. // Check if the page is a valid page.