Skip to content

Commit 3ac1c45

Browse files
authored
Merge pull request #578 from kss2002/feat/scroll-top
feat(landing): add scroll-to-top on route change for detail pages
2 parents a1517bc + f5b14bb commit 3ac1c45

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use client'
2+
3+
import { useScrollToTop } from '@/hooks/use-scroll-top'
4+
5+
export function ScrollToTop() {
6+
useScrollToTop()
7+
return null
8+
}

apps/landing/src/app/(detail)/components/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { Box, Flex } from '@devup-ui/react'
22

33
import { RightIndex } from '../docs/RightIndex'
44
import { LeftMenu } from './LeftMenu'
5+
import { ScrollToTop } from './ScrollToTop'
56

67
export default function Layout({
78
children,
89
}: Readonly<{ children: React.ReactNode }>) {
910
return (
1011
<>
12+
<ScrollToTop />
1113
<Flex maxW="1920px" minH="calc(100vh - 500px)" mx="auto">
1214
<Box display={['none', null, 'initial']} p="20px 16px" w="220px">
1315
<Box pos="sticky" top={['70px', null, '90px']}>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use client'
2+
import { useLenis } from 'lenis/react'
3+
import { usePathname } from 'next/navigation'
4+
import { useEffect } from 'react'
5+
6+
export function useScrollToTop() {
7+
const pathname = usePathname()
8+
const lenis = useLenis()
9+
10+
useEffect(() => {
11+
lenis?.scrollTo(0, { immediate: true })
12+
}, [lenis, pathname])
13+
}

0 commit comments

Comments
 (0)