feat(routing): pass the new url to pageChange event

This commit is contained in:
Maieul BOYER 2026-01-04 14:57:30 +01:00 committed by Maix0
parent 6f89e4a3e1
commit 9947970f63
2 changed files with 8 additions and 11 deletions

View file

@ -1,19 +1,15 @@
import { type State } from "ft_state";
interface CustomEventMap {
"ft:pageChange": CustomEvent<{}>;
"ft:pageChange": CustomEvent<string>;
}
declare global {
interface Document {
//adds definition to Document, but you can do the same with HTMLElement
addEventListener<K extends keyof CustomEventMap>(
type: K,
listener: (this: Document, ev: CustomEventMap[K]) => void,
): void;
dispatchEvent<K extends keyof CustomEventMap>(
ev: CustomEventMap[K],
): void;
addEventListener<K extends keyof CustomEventMap>(type: K,
listener: (this: Document, ev: CustomEventMap[K]) => void): void;
dispatchEvent<K extends keyof CustomEventMap>(ev: CustomEventMap[K]): void;
}
}

View file

@ -205,9 +205,10 @@ export async function handleRoute() {
`/login?returnTo=${encodeURIComponent(window.location.pathname)}`,
);
const app = document.getElementById("app")!;
document.dispatchEvent(
new CustomEvent("ft:pageChange" as any, {} as any) as any,
);
const event = new CustomEvent("ft:pageChange", { detail: window.location.pathname });
document.dispatchEvent(event);
let ret = await executeRouteHandler(
route_handler,
window.location.pathname,