Skip to content

Commit 0ee70ed

Browse files
ozkeisarclaude
andcommitted
fix: Download buttons now work from all pages
- Update Button component to navigate to home page with hash when on other pages - Update Footer with same cross-page anchor navigation - Update ScrollToTop to handle hash-based scrolling after navigation - Download buttons in Header now work from /features, /privacy, /terms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 8959a89 commit 0ee70ed

3 files changed

Lines changed: 43 additions & 12 deletions

File tree

src/App.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,22 @@ import Privacy from './pages/Privacy'
88
import Terms from './pages/Terms'
99

1010
function 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
}

src/components/layout/Footer.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Link } from 'react-router-dom'
1+
import { Link, useLocation, useNavigate } from 'react-router-dom'
22
import { Container } from '../ui/Container'
33
import { Github, Twitter, Mail } from 'lucide-react'
44
import { AdditLogo } from '../ui/AdditLogo'
@@ -25,6 +25,21 @@ const socialLinks = [
2525
]
2626

2727
export 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}

src/components/ui/Button.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ReactNode, MouseEvent } from 'react'
2-
import { Link } from 'react-router-dom'
2+
import { Link, useLocation, useNavigate } from 'react-router-dom'
33
import { motion } from 'framer-motion'
44

55
interface 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' })

0 commit comments

Comments
 (0)