Skip to content

Commit 38f38e7

Browse files
authored
Merge pull request #313 from prgrms-web-devcourse-final-project/feat/modal-scroll-lock
[feat] scrollLock state 전달하여 스크롤 이동 제어
2 parents f06decd + 0bb5f12 commit 38f38e7

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

src/components/ScrollToTop.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import { useEffect } from 'react';
22
import { useLocation } from 'react-router';
33

44
function ScrollToTop() {
5-
const { pathname } = useLocation();
5+
const { pathname, state } = useLocation();
66

77
useEffect(() => {
8+
if (state?.scrollLock) return; // scrollLock이 true면 스크롤 안 함
9+
810
window.scrollTo({
911
top: 0,
1012
});

src/components/modalSheet/BackLink.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ const BackLink = () => {
77
pathSegments.pop(); // 마지막 세그먼트 제거
88
const newPath = '/' + pathSegments.join('/');
99
return (
10-
<Link to={newPath} className="flex items-center justify-center w-6 h-6 cursor-pointer">
10+
<Link
11+
to={newPath}
12+
state={{ scrollLock: true }}
13+
className="flex items-center justify-center w-6 h-6 cursor-pointer"
14+
>
1115
<img src={closeIcon} alt="닫기" />
1216
</Link>
1317
);

src/components/user/EmotionRecordCardList.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ function EmotionRecordCardList({ records, basePath }: EmotionRecordCardListProps
2121
<EmotionRecordCard
2222
key={record.recordId}
2323
record={record}
24-
onClick={() => navigate(`${basePath}/${record.recordId}`)}
24+
onClick={() =>
25+
navigate(`${basePath}/${record.recordId}`, {
26+
state: { scrollLock: true },
27+
})
28+
}
2529
/>
2630
))}
2731
</div>

src/layouts/bottomNav/BottomNav.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default function BottomNav() {
4343
//메인 페이지
4444
location.pathname === '/home' ||
4545
//마이 페이지
46-
location.pathname === '/mypage' ||
46+
location.pathname.startsWith('/mypage') ||
4747
//유저 페이지
4848
location.pathname.startsWith('/user') ||
4949
//지난 대화 기록 페이지

0 commit comments

Comments
 (0)