From 8b75f7c64d49de13574a56a3637e62de083d12d0 Mon Sep 17 00:00:00 2001 From: Junhyuck Ko Date: Sat, 15 Jul 2023 11:31:03 +0900 Subject: [PATCH] work in process --- .../NavigationBar/NavigationBar.tsx | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/components/NavigationBar/NavigationBar.tsx b/src/components/NavigationBar/NavigationBar.tsx index 9b9cc08..24acb2a 100644 --- a/src/components/NavigationBar/NavigationBar.tsx +++ b/src/components/NavigationBar/NavigationBar.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import classNames from 'classnames'; import dynamic from 'next/dynamic'; import { Noto_Sans_KR } from 'next/font/google'; @@ -105,6 +105,33 @@ const Right = () => { }; const Middle = () => { + const router = useRouter(); + const [isShowing, setIsShowing] = useState(false); + const [postTitle, setPostTitle] = useState(''); + + useEffect(() => { + const isPostPath = getSubDomain(router.pathname) === 'posts'; + setIsShowing(isPostPath); + }, [router.pathname]); + + useEffect(() => { + const handler = () => { + const title = document.querySelector('.post-title'); + + if (!title) return; + + setPostTitle(title.textContent || ''); + }; + + handler(); + + router.events.on('routeChangeComplete', handler); + + return () => { + router.events.off('routeChangeComplete', handler); + }; + }, [router.events]); + return (
{ 'text-center' )} > - Test + {postTitle}
); };