diff options
| author | Maksymilian Jopek <maks@jopek.eu> | 2023-11-15 19:29:24 +0100 |
|---|---|---|
| committer | Maksymilian Jopek <maks@jopek.eu> | 2023-11-15 19:34:12 +0100 |
| commit | 857c528369473a66518407dee6f6cac89bbc538c (patch) | |
| tree | cccf02a369ee6cafb2a89750ee222ebba69d2269 /src/Router.tsx | |
| download | listeya-xelata-nobele-857c528369473a66518407dee6f6cac89bbc538c.tar.gz listeya-xelata-nobele-857c528369473a66518407dee6f6cac89bbc538c.tar.zst listeya-xelata-nobele-857c528369473a66518407dee6f6cac89bbc538c.zip | |
Diffstat (limited to 'src/Router.tsx')
| -rw-r--r-- | src/Router.tsx | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/Router.tsx b/src/Router.tsx new file mode 100644 index 0000000..eb4cf21 --- /dev/null +++ b/src/Router.tsx @@ -0,0 +1,30 @@ +import { useEffect, useState } from "react"; +import Search from "./Search"; +import Table from "./Table"; + +const startPath = + location.pathname.at(-1) === "/" + ? location.pathname + : location.pathname + "/"; +export default function Router() { + const [path, setPath] = useState(""); + useEffect(() => { + setPath(location.pathname); + }, []); + window.addEventListener("popstate", () => { + setPath(location.pathname); + }); + + function updatePath(newPath: string) { + console.log({ newPath, startPath }); + const path = startPath + newPath; + history.pushState({}, "", path); + setPath(path); + } + + if (path.includes("/nagrody/")) { + return <Table />; + } else { + return <Search setPath={updatePath} />; + } +} |
