diff --git a/frontend/src/components/common/ScrollToTop.jsx b/frontend/src/components/common/ScrollToTop.jsx index 99bcedc..5b50752 100644 --- a/frontend/src/components/common/ScrollToTop.jsx +++ b/frontend/src/components/common/ScrollToTop.jsx @@ -16,6 +16,12 @@ function ScrollToTop() { if (mobileContent) { mobileContent.scrollTop = 0; } + + // PC 레이아웃 스크롤 컨테이너 초기화 + const main = document.querySelector('main'); + if (main) { + main.scrollTop = 0; + } }, [pathname]); return null; diff --git a/frontend/src/pages/mobile/album/TrackDetail.jsx b/frontend/src/pages/mobile/album/TrackDetail.jsx index 2e76f45..b50cca3 100644 --- a/frontend/src/pages/mobile/album/TrackDetail.jsx +++ b/frontend/src/pages/mobile/album/TrackDetail.jsx @@ -1,4 +1,4 @@ -import { useState, useMemo, useEffect } from 'react'; +import { useState, useMemo, useEffect, useLayoutEffect } from 'react'; import { useParams, useNavigate, Link } from 'react-router-dom'; import { useQuery } from '@tanstack/react-query'; import { motion } from 'framer-motion'; @@ -40,6 +40,11 @@ function MobileTrackDetail() { const youtubeVideoId = useMemo(() => getYoutubeVideoId(track?.video_url), [track?.video_url]); const videoLabel = track?.video_type === 'special' ? '스페셜 영상' : '뮤직비디오'; + // 트랙 변경 시 스크롤 맨 위로 + useLayoutEffect(() => { + window.scrollTo({ top: 0, behavior: 'instant' }); + }, [trackTitle]); + // 가사 펼침 상태 const [showFullLyrics, setShowFullLyrics] = useState(false); @@ -93,7 +98,7 @@ function MobileTrackDetail() { } return ( -
+
{/* 트랙 정보 헤더 */} getYoutubeVideoId(track?.video_url), [track?.video_url]); const videoLabel = track?.video_type === 'special' ? '스페셜 영상' : '뮤직비디오'; + // 트랙 변경 시 스크롤 맨 위로 + useLayoutEffect(() => { + const main = document.querySelector('main'); + if (main) { + main.scrollTop = 0; + } + }, [trackTitle]); + if (loading) { return ( +
{/* 브레드크럼 네비게이션 */}
@@ -218,11 +232,18 @@ function PCTrackDetail() { {track.otherTracks?.map((t) => { const isCurrent = t.title === track.title; return ( - { + if (!isCurrent) { + navigate( + `/album/${encodeURIComponent(track.album?.title || albumName)}/track/${encodeURIComponent(t.title)}`, + { replace: true } + ); + } + }} + className={`w-full group flex items-center gap-3 px-3 py-2.5 rounded-xl transition-all ${ isCurrent ? 'bg-primary text-white' : 'hover:bg-gray-50' }`} > @@ -259,7 +280,7 @@ function PCTrackDetail() { {t.duration || ''} - + ); })}