Skip to content

Commit dc0efe2

Browse files
committed
feat: basePath 추가
1 parent 02b77bc commit dc0efe2

File tree

6 files changed

+26
-8
lines changed

6 files changed

+26
-8
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Link, useLocation } from 'react-router';
2+
import closeIcon from '@assets/icons/close-icon.svg';
3+
const BackLink = () => {
4+
const location = useLocation();
5+
6+
const pathSegments = location.pathname.split('/').filter(Boolean); // ['', 'post', '123'] → ['post', '123']
7+
pathSegments.pop(); // 마지막 세그먼트 제거
8+
const newPath = '/' + pathSegments.join('/');
9+
return (
10+
<Link to={newPath} className="flex items-center justify-center w-6 h-6 cursor-pointer">
11+
<img src={closeIcon} alt="닫기" />
12+
</Link>
13+
);
14+
};
15+
16+
export default BackLink;

src/components/user/EmotionRecordCardList.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { InfoMessage, EmotionRecordCard } from '@/components';
22
import { useNavigate } from 'react-router';
33
interface EmotionRecordCardListProps {
44
records: EmotionRecord[];
5+
basePath: string;
56
}
67

7-
function EmotionRecordCardList({ records }: EmotionRecordCardListProps) {
8+
function EmotionRecordCardList({ records, basePath }: EmotionRecordCardListProps) {
89
const navigate = useNavigate();
910
if (records.length === 0) {
1011
return (
@@ -20,7 +21,7 @@ function EmotionRecordCardList({ records }: EmotionRecordCardListProps) {
2021
<EmotionRecordCard
2122
key={record.recordId}
2223
record={record}
23-
onClick={() => navigate(`/mypage/${record.recordId}`)}
24+
onClick={() => navigate(`${basePath}/${record.recordId}`)}
2425
/>
2526
))}
2627
</div>

src/components/user/EmotionRecordSection.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import { useInView } from 'react-intersection-observer';
55

66
interface EmotionRecordSectionProps {
77
records: EmotionRecord[];
8+
basePath: string;
89
fetchNextPage: () => void;
910
hasNextPage: boolean;
1011
isFetchingNextPage: boolean;
1112
}
1213

1314
const EmotionRecordSection = ({
1415
records,
16+
basePath,
1517
fetchNextPage,
1618
hasNextPage,
1719
isFetchingNextPage,
@@ -28,7 +30,7 @@ const EmotionRecordSection = ({
2830

2931
return (
3032
<div className="flex flex-col items-center">
31-
<EmotionRecordCardList records={records} />
33+
<EmotionRecordCardList basePath={basePath} records={records} />
3234
{hasNextPage && !isFetchingNextPage && (
3335
<div ref={ref}>
3436
<LoadingMini />

src/layouts/ModalSheetLayoutTemp.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import BackLink from '@/components/modalSheet/BackLink';
12
import CardDetailMoreMenu from '@/components/modalSheet/CardDetailMoreMenu';
2-
import closeIcon from '@assets/icons/close-icon.svg';
33
import { motion } from 'framer-motion';
4-
import { Link } from 'react-router';
54

65
interface ModalSheetLayoutProps {
76
children: React.ReactNode;
@@ -28,9 +27,7 @@ function ModalSheetLayoutTemp({ children, isOwnPost }: ModalSheetLayoutProps) {
2827
<div className="max-w-[600px] w-full h-screen flex flex-col bg-white rounded-lg card-shadow border border-gray-5 overflow-y-auto scroll">
2928
{/* 헤더 */}
3029
<div className="sticky top-0 flex h-[60px] items-center px-4 justify-between bg-white">
31-
<Link to={'/mypage'} className="flex items-center justify-center w-6 h-6 cursor-pointer">
32-
<img src={closeIcon} alt="닫기" />
33-
</Link>
30+
<BackLink />
3431
{isOwnPost && <CardDetailMoreMenu />}
3532
</div>
3633
{children}

src/pages/mypage/components/MyEmotionRecordSection.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const MyEmotionRecordSection = () => {
1414
return (
1515
<EmotionRecordSection
1616
records={records}
17+
basePath="/mypage"
1718
fetchNextPage={fetchNextPage}
1819
hasNextPage={hasNextPage}
1920
isFetchingNextPage={isFetchingNextPage}

src/pages/userpage/components/UserEmotionRecordSection.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const UserEmotionRecordSection = ({ userId }: UserEmotionRecordSectionProps) =>
1717

1818
return (
1919
<EmotionRecordSection
20+
basePath={`/user/${userId}`}
2021
records={records}
2122
fetchNextPage={fetchNextPage}
2223
hasNextPage={hasNextPage}

0 commit comments

Comments
 (0)