mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-26 23:32:43 +00:00
Fix base route navigation
This commit is contained in:
parent
5ac93645e4
commit
18c143e12f
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user