From 18c143e12fce0ee4a03ed69e5d0526cd8e77ef39 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Mon, 10 Apr 2023 01:16:53 -0400 Subject: [PATCH] Fix base route navigation --- src/handbook/src/backend/events.ts | 6 ++++-- src/handbook/src/backend/types.ts | 2 +- src/handbook/src/ui/App.tsx | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/handbook/src/backend/events.ts b/src/handbook/src/backend/events.ts index cf132f197..8904b8c2b 100644 --- a/src/handbook/src/backend/events.ts +++ b/src/handbook/src/backend/events.ts @@ -1,5 +1,7 @@ import { EventEmitter } from "events"; + import type { Page } from "@backend/types"; +import { isPage } from "@backend/types"; const emitter = new EventEmitter(); const navigation = new EventEmitter(); @@ -18,14 +20,14 @@ export function setup(): void { setTimeout(() => { // Check if the window's href is a page. const page = window.location.href.split("/").pop(); - if (page == undefined) return; + if (page == undefined || page == "") return; // Convert the page to a Page type. const pageName = page.charAt(0).toUpperCase() + page.slice(1); const pageType = pageName as Page; // Navigate to the page. - navigate(pageType, false); + isPage(page) && navigate(pageType, false); }, 3e2); } diff --git a/src/handbook/src/backend/types.ts b/src/handbook/src/backend/types.ts index 0e83545c5..5213fe621 100644 --- a/src/handbook/src/backend/types.ts +++ b/src/handbook/src/backend/types.ts @@ -124,7 +124,7 @@ export enum ItemCategory { * @param page The string to check. */ export function isPage(page: string): page is Page { - return ["Home", "Commands"].includes(page); + return ["Home", "Commands", "Avatars", "Items", "Entities", "Scenes"].includes(page); } /** diff --git a/src/handbook/src/ui/App.tsx b/src/handbook/src/ui/App.tsx index 25f606907..ca7f21787 100644 --- a/src/handbook/src/ui/App.tsx +++ b/src/handbook/src/ui/App.tsx @@ -23,7 +23,9 @@ class App extends React.Component<{}, IState> { // Check if the window's href is a page. let targetPage = null; const page = window.location.href.split("/").pop(); - if (page != undefined) { + console.log(page) + + if (page != undefined && page != "") { // Convert the page to a Page type. const pageName = page.charAt(0).toUpperCase() + page.slice(1); // Check if the page is a valid page.