diff --git a/components/post-toc.tsx b/components/post-toc.tsx index 2294f61..6a6908b 100644 --- a/components/post-toc.tsx +++ b/components/post-toc.tsx @@ -1,6 +1,7 @@ 'use client'; import { useEffect, useRef, useState } from 'react'; +import { usePathname } from 'next/navigation'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faListUl } from '@fortawesome/free-solid-svg-icons'; @@ -16,6 +17,7 @@ export function PostToc({ onLinkClick }: { onLinkClick?: () => void }) { const listRef = useRef(null); const itemRefs = useRef>({}); const [indicator, setIndicator] = useState({ top: 0, opacity: 0 }); + const pathname = usePathname(); useEffect(() => { const headings = Array.from( @@ -51,7 +53,7 @@ export function PostToc({ onLinkClick }: { onLinkClick?: () => void }) { headings.forEach((el) => observer.observe(el)); return () => observer.disconnect(); - }, []); + }, [pathname]); useEffect(() => { if (!activeId || !listRef.current) {