diff --git a/frontend/src/ts/controllers/route-controller.ts b/frontend/src/ts/controllers/route-controller.ts index 7838bb937..a8fa6b771 100644 --- a/frontend/src/ts/controllers/route-controller.ts +++ b/frontend/src/ts/controllers/route-controller.ts @@ -15,6 +15,11 @@ import { Auth } from "../firebase"; //source: https://www.youtube.com/watch?v=OstALBk-jTc // https://www.youtube.com/watch?v=OstALBk-jTc +//this will be used in tribe +interface NavigateOptions { + empty?: boolean; +} + function pathToRegex(path: string): RegExp { return new RegExp( "^" + path.replace(/\//g, "\\/").replace(/:\w+/g, "(.+)") + "$" @@ -34,7 +39,10 @@ function getParams(match: { route: Route; result: RegExpMatchArray }): { interface Route { path: string; - load: (params: { [key: string]: string }) => void; + load: ( + params: { [key: string]: string }, + navigateOptions: NavigateOptions + ) => void; } const routes: Route[] = [ @@ -101,7 +109,10 @@ const routes: Route[] = [ }, ]; -export function navigate(url = window.location.pathname): void { +export function navigate( + url = window.location.pathname, + options = {} as NavigateOptions +): void { if ( TestUI.testRestarting || TestUI.resultCalculating || @@ -112,10 +123,10 @@ export function navigate(url = window.location.pathname): void { url = url.replace(/\/$/, ""); if (url === "") url = "/"; history.pushState(null, "", url); - router(); + router(options); } -async function router(): Promise { +async function router(options = {} as NavigateOptions): Promise { const matches = routes.map((r) => { return { route: r, @@ -133,10 +144,12 @@ async function router(): Promise { return; } - match.route.load(getParams(match)); + match.route.load(getParams(match), options); } -window.addEventListener("popstate", router); +window.addEventListener("popstate", () => { + router(); +}); document.addEventListener("DOMContentLoaded", () => { document.body.addEventListener("click", (e) => {