Skip to content

Commit

Permalink
fix: 뒤로가기 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
gyeongza committed Jul 19, 2024
1 parent 6c0080a commit d0cd41a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/shared/components/Header/HeaderWithBackRoute/index.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<header className="w-full flex items-center">
<nav className="w-[1080px] h-[70px] flex items-center justify-between mx-auto border-b">
Expand Down

0 comments on commit d0cd41a

Please sign in to comment.