File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { useEffect } from 'react'
2+ import { useLocation } from 'react-router-dom'
13import { SiteNav } from '@/widgets/site-nav'
24import { HomeHero } from '@/widgets/home-hero'
35import { HomeServices } from '@/widgets/home-services'
@@ -7,6 +9,23 @@ import { HomeCta } from '@/widgets/home-cta'
79import { SiteFooter } from '@/widgets/site-footer'
810
911export 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 />
Original file line number Diff line number Diff line change @@ -3,9 +3,9 @@ import { Link } from 'react-router-dom'
33import { useAuth , useLogout } from '@/features/auth'
44
55const 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
1111export 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
You can’t perform that action at this time.
0 commit comments