Skip to content

Commit bc33942

Browse files
i3monthsclaude
andcommitted
fix(site-nav): 섹션 앵커를 홈 절대경로로 + 홈에서 hash 스크롤 처리
네비바는 모든 페이지에 렌더되는데 Services/About/FAQ/로고가 인페이지 앵커(#services 등)라 홈이 아닌 페이지에서 누르면 URL 에 # 만 붙고 동작하지 않았음. - SiteNav: 섹션 링크·로고를 Link to="/#services" 등 홈 절대경로로 - HomePage: useLocation().hash 기반 scrollIntoView effect 추가 (클라이언트 이동·풀 리로드 모두에서 해당 섹션으로 스크롤) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 1fe5e28 commit bc33942

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

frontend/src/pages/Home/ui/HomePage.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useEffect } from 'react'
2+
import { useLocation } from 'react-router-dom'
13
import { SiteNav } from '@/widgets/site-nav'
24
import { HomeHero } from '@/widgets/home-hero'
35
import { HomeServices } from '@/widgets/home-services'
@@ -7,6 +9,23 @@ import { HomeCta } from '@/widgets/home-cta'
79
import { SiteFooter } from '@/widgets/site-footer'
810

911
export default function HomePage() {
12+
const { hash } = useLocation()
13+
14+
// 다른 페이지 또는 풀 리로드로 진입할 때 #section 으로 스크롤.
15+
// (라우터는 hash 스크롤을 보장하지 않고, 풀 리로드 시 엘리먼트가
16+
// 아직 마운트 전이라 브라우저 기본 스크롤이 빗나감)
17+
useEffect(() => {
18+
const id = hash.replace('#', '')
19+
if (!id) {
20+
window.scrollTo({ top: 0 })
21+
return
22+
}
23+
const raf = requestAnimationFrame(() => {
24+
document.getElementById(id)?.scrollIntoView({ behavior: 'smooth' })
25+
})
26+
return () => cancelAnimationFrame(raf)
27+
}, [hash])
28+
1029
return (
1130
<div className="min-h-svh bg-bg text-fg">
1231
<SiteNav />

frontend/src/widgets/site-nav/ui/SiteNav.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { Link } from 'react-router-dom'
33
import { useAuth, useLogout } from '@/features/auth'
44

55
const items = [
6-
{ href: '#services', label: 'Services' },
7-
{ href: '#quote', label: 'About' },
8-
{ href: '#faq', label: 'FAQ' },
6+
{ to: '/#services', label: 'Services' },
7+
{ to: '/#quote', label: 'About' },
8+
{ to: '/#faq', label: 'FAQ' },
99
]
1010

1111
export function SiteNav() {
@@ -31,22 +31,22 @@ export function SiteNav() {
3131
style={{ zIndex: 'var(--z-sticky)' }}
3232
>
3333
<div className="mx-auto max-w-content px-6 lg:px-12 h-16 flex items-center justify-between">
34-
<a
35-
href="#top"
34+
<Link
35+
to="/#top"
3636
className="font-heading font-extrabold tracking-[0.04em] text-sage-900 text-[15px] uppercase"
3737
>
3838
Stack Up
39-
</a>
39+
</Link>
4040

4141
<nav aria-label="Primary" className="hidden md:flex items-center gap-1">
4242
{items.map((it) => (
43-
<a
44-
key={it.href}
45-
href={it.href}
43+
<Link
44+
key={it.to}
45+
to={it.to}
4646
className="px-3 py-2 text-button text-fg-strong/80 hover:text-fg-strong transition-colors duration-fast"
4747
>
4848
{it.label}
49-
</a>
49+
</Link>
5050
))}
5151
</nav>
5252

0 commit comments

Comments
 (0)