web: separate search route
This commit is contained in:
18
web/src/root-router.tsx
Normal file
18
web/src/root-router.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
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 />;
|
||||
}
|
||||
Reference in New Issue
Block a user