From d0cd41a5ce34acb916c9b6e9e58b431b80218710 Mon Sep 17 00:00:00 2001 From: gyeongza Date: Fri, 19 Jul 2024 16:48:22 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=92=A4=EB=A1=9C=EA=B0=80=EA=B8=B0=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Header/HeaderWithBackRoute/index.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/shared/components/Header/HeaderWithBackRoute/index.tsx b/src/shared/components/Header/HeaderWithBackRoute/index.tsx index 57f65d9..9b26807 100644 --- a/src/shared/components/Header/HeaderWithBackRoute/index.tsx +++ b/src/shared/components/Header/HeaderWithBackRoute/index.tsx @@ -1,16 +1,19 @@ import { ArrowBack } from '@/shared/assets/Icons'; -import { useRouter } from 'next/navigation'; +import { useRouter, usePathname } from 'next/navigation'; const HeaderWithBackRoute = () => { const router = useRouter(); + const pathName = usePathname(); + + const getProductCategory = () => { + const parts = pathName.split('/'); + return parts.length > 2 ? parts[2] : ''; + }; const goToBackPage = () => { - if (window.history.length > 1) { - router.back(); - } else { - router.push('/category/macbook_air'); - } + router.push(`/category/${getProductCategory()}`); }; + return (