Files
Sybil-2/web/src/root-router.tsx

19 lines
530 B
TypeScript

import { useEffect, useState } from "preact/hooks";
import App from "@/App";
import SearchRoutePage from "@/pages/search-route-page";
export function RootRouter() {
const [path, setPath] = useState(window.location.pathname);
useEffect(() => {
const onPopState = () => setPath(window.location.pathname);
window.addEventListener("popstate", onPopState);
return () => window.removeEventListener("popstate", onPopState);
}, []);
if (path === "/search") {
return <SearchRoutePage />;
}
return <App />;
}