diff --git a/app/routes/learn.tsx b/app/routes/learn.tsx index e9743f7..a9c2304 100644 --- a/app/routes/learn.tsx +++ b/app/routes/learn.tsx @@ -1,12 +1,19 @@ -import { useState } from "react"; +import { useEffect } from "react"; import { Link, useLocation } from "react-router"; import BasicRule from "~/lib/components/BasicRule"; import LocalRule from "~/lib/components/LocalRule"; export default function Page() { const location = useLocation(); - const [currentHash] = useState(location.hash); - const contents = ["basic", "local"]; + const currentHash = location.hash; + const contents = ["basic", "local"] as const; + + useEffect(() => { + if (!currentHash) return; + const el = document.querySelector(currentHash); + el?.scrollIntoView({ behavior: "smooth" }); + }, [currentHash]); + return (
@@ -24,39 +31,28 @@ export default function Page() {
-
+ />
+