diff --git a/src/components/common/HeaderCloseIcon.tsx b/src/components/common/HeaderCloseIcon.tsx index 494bed4..11e6e93 100644 --- a/src/components/common/HeaderCloseIcon.tsx +++ b/src/components/common/HeaderCloseIcon.tsx @@ -4,7 +4,6 @@ import { useNavigateTo } from '@/hooks/useNavigateTo'; import { iconPropsGenerator } from '@/utils/iconPropsGenerator'; import { useRecoilState } from 'recoil'; -//기능 추가필요(useClose수정) const HeaderCloseIcon = () => { const goToBack = useNavigateTo('-1'); const [footerState, setFooterState] = useRecoilState(footerShowState); diff --git a/src/components/post/PostRegister.tsx b/src/components/post/PostRegister.tsx index 99f7929..f8c40d4 100644 --- a/src/components/post/PostRegister.tsx +++ b/src/components/post/PostRegister.tsx @@ -1,6 +1,6 @@ import { useEffect, useRef } from 'react'; import { useNavigate } from 'react-router-dom'; -import { useRecoilValue, useResetRecoilState } from 'recoil'; +import { useRecoilValue } from 'recoil'; import { nanoid } from 'nanoid'; import CoffeeMenuSelection from '@/components/home/CoffeeMenuSelection'; @@ -142,7 +142,10 @@ const PostRegister = ({ : await handleUpdate(); await updateTodayCoffeeData(); URL.revokeObjectURL(imageUrl); - registered && navigate(`/post/${postId}`); + registered && + navigate(`/post/${postId}`, { + state: true + }); }; return ( diff --git a/src/hooks/useNavigateTo.ts b/src/hooks/useNavigateTo.ts index efa9067..1656176 100644 --- a/src/hooks/useNavigateTo.ts +++ b/src/hooks/useNavigateTo.ts @@ -1,8 +1,12 @@ -import { useNavigate } from 'react-router-dom'; - +import { useLocation, useNavigate } from 'react-router-dom'; export const useNavigateTo = (to: string) => { + const { pathname, state } = useLocation(); const navigate = useNavigate(); + const registered = pathname.includes('post') && state; const toWhere = () => { + if (registered && to === '-1') { + return navigate('/'); + } if (to === '-1') { navigate(-1); return;