File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,11 +8,22 @@ import Privacy from './pages/Privacy'
88import Terms from './pages/Terms'
99
1010function ScrollToTop ( ) {
11- const { pathname } = useLocation ( )
11+ const { pathname, hash } = useLocation ( )
1212
1313 useEffect ( ( ) => {
14- window . scrollTo ( 0 , 0 )
15- } , [ pathname ] )
14+ // If there's a hash, scroll to the element
15+ if ( hash ) {
16+ // Small delay to ensure the DOM is ready
17+ setTimeout ( ( ) => {
18+ const element = document . querySelector ( hash )
19+ if ( element ) {
20+ element . scrollIntoView ( { behavior : 'smooth' } )
21+ }
22+ } , 100 )
23+ } else {
24+ window . scrollTo ( 0 , 0 )
25+ }
26+ } , [ pathname , hash ] )
1627
1728 return null
1829}
Original file line number Diff line number Diff line change 1- import { Link } from 'react-router-dom'
1+ import { Link , useLocation , useNavigate } from 'react-router-dom'
22import { Container } from '../ui/Container'
33import { Github , Twitter , Mail } from 'lucide-react'
44import { AdditLogo } from '../ui/AdditLogo'
@@ -25,6 +25,21 @@ const socialLinks = [
2525]
2626
2727export default function Footer ( ) {
28+ const location = useLocation ( )
29+ const navigate = useNavigate ( )
30+
31+ const handleAnchorClick = ( e : React . MouseEvent , href : string ) => {
32+ e . preventDefault ( )
33+ if ( location . pathname !== '/' ) {
34+ navigate ( '/' + href )
35+ return
36+ }
37+ const element = document . querySelector ( href )
38+ if ( element ) {
39+ element . scrollIntoView ( { behavior : 'smooth' } )
40+ }
41+ }
42+
2843 return (
2944 < footer className = "border-t border-white/5 bg-background" >
3045 < Container >
@@ -71,13 +86,7 @@ export default function Footer() {
7186 ) : link . href . startsWith ( '#' ) ? (
7287 < a
7388 href = { link . href }
74- onClick = { ( e ) => {
75- e . preventDefault ( )
76- const element = document . querySelector ( link . href )
77- if ( element ) {
78- element . scrollIntoView ( { behavior : 'smooth' } )
79- }
80- } }
89+ onClick = { ( e ) => handleAnchorClick ( e , link . href ) }
8190 className = "text-foreground-secondary hover:text-white transition-colors text-sm"
8291 >
8392 { link . name }
Original file line number Diff line number Diff line change 11import { ReactNode , MouseEvent } from 'react'
2- import { Link } from 'react-router-dom'
2+ import { Link , useLocation , useNavigate } from 'react-router-dom'
33import { motion } from 'framer-motion'
44
55interface ButtonProps {
@@ -35,6 +35,9 @@ export function Button({
3535 className = '' ,
3636 disabled = false ,
3737} : ButtonProps ) {
38+ const location = useLocation ( )
39+ const navigate = useNavigate ( )
40+
3841 const baseClasses = `
3942 inline-flex items-center justify-center gap-2
4043 font-medium rounded-lg
@@ -66,6 +69,14 @@ export function Button({
6669 if ( href . startsWith ( '#' ) ) {
6770 const handleClick = ( e : MouseEvent < HTMLAnchorElement > ) => {
6871 e . preventDefault ( )
72+
73+ // If not on home page, navigate to home first with the hash
74+ if ( location . pathname !== '/' ) {
75+ navigate ( '/' + href )
76+ return
77+ }
78+
79+ // On home page, just scroll to the element
6980 const element = document . querySelector ( href )
7081 if ( element ) {
7182 element . scrollIntoView ( { behavior : 'smooth' } )
You can’t perform that action at this time.
0 commit comments