# Fix: Navigation & Router Links Causing Full Page Reloads ## Problem Internal navigation links cause full page reloads instead of client-side routing. Root causes: 1. **RollingTextLink** (`src/components/ui/RollingTextLink.tsx`) — renders `` for all nav items 2. **Button** (`src/components/ui/Button.tsx`) — renders `` for all href values, including internal routes 3. **Projects** (`src/components/sections/Projects.tsx`) — uses `` and `` ## Changes ### 1. `src/components/ui/RollingTextLink.tsx` Replace `` with React Router ``. ```diff import { Link } from "react-router" - return ( - { hovered.current = true; requestActive(true) }} - onPointerLeave={() => { hovered.current = false; requestActive(focused.current) }} - onFocus={() => { focused.current = true; requestActive(true) }} - onBlur={() => { focused.current = false; requestActive(hovered.current) }} - > + return ( + { hovered.current = true; requestActive(true) }} + onPointerLeave={() => { hovered.current = false; requestActive(focused.current) }} + onFocus={() => { focused.current = true; requestActive(true) }} + onBlur={() => { focused.current = false; requestActive(hovered.current) }} + > {children} {children} - + ) ``` **Rationale:** `` renders an `` element under the hood but intercepts click events for client-side navigation. Animation event handlers (`onPointerEnter`, `onFocus`, etc.) work identically since the DOM element is the same. --- ### 2. `src/components/ui/Button.tsx` Detect internal routes (`href` starts with `/`) → use `motion(Link)`. External URLs keep `motion.a`. ```diff import { Link } from "react-router" type ButtonVariant = "primary" | "secondary" | "ghost" type ButtonSize = "sm" | "md" | "lg" interface ButtonProps extends ComponentPropsWithoutRef<"button"> { variant?: ButtonVariant size?: ButtonSize href?: string download?: boolean children: React.ReactNode } // ... variantClasses, sizeClasses unchanged ... export const Button = forwardRef< HTMLButtonElement | HTMLAnchorElement, ButtonProps >( ( { variant = "primary", size = "md", href, className = "", children, + download, ...props }, ref ) => { const classes = `${variantClasses[variant]} ${sizeClasses[size]} ${className}`.trim() if (href) { + const isRoute = href.startsWith("/") + const safeProps = { ...props } + if (isRoute) { + delete (safeProps as Record)["download"] + } + + if (isRoute) { + return ( + } + whileTap={{ scale: 0.95 }} + {...(safeProps as Omit< + React.AnchorHTMLAttributes, + keyof ButtonProps | "to" + >)} + > + {children} + + ) + } + return ( } whileTap={{ scale: 0.95 }} {...(props as Omit, keyof ButtonProps>)} > {children} ) } return ( } whileTap={{ scale: 0.95 }} {...(props as Omit, keyof ButtonProps>)} > {children} ) } ) ``` **Rationale:** - Internal routes (`/projects`, `/contact`) → `motion(Link)` for client-side nav - External URLs (GitHub, LinkedIn) → `motion.a` unchanged - `download` prop stripped for internal routes (invalid on ``, no-op on same-origin ``) --- ### 3. `src/components/sections/Projects.tsx` Replace `` with `motion(Link)` for project cards and "View All" link. ```diff import { Link } from "react-router" import { motion } from "motion/react" import { Badge } from "@/components/ui/Badge" import { projects } from "@/data/projects" import { InView } from "@/components/ui/InView" // ... categoryLabels, Projects function start unchanged ...

Featured Projects

- + View All → - +
{featured.map((project, i) => ( - {/* card content unchanged */} - + ))}
``` **Rationale:** `motion(Link)` passes `whileHover`/`whileTap` to the underlying `
` element. Animation behavior is identical. --- ### 4. `src/components/sections/Hero.tsx` Replace `download` with `target="_blank"` for resume PDF link. ```diff - ``` **Rationale:** - `download` attribute has no effect on same-origin URLs (browsers ignore it) - Button already strips `download` for internal routes (now `/resume.pdf` is treated as a route) - `target="_blank"` opens PDF in new tab, which is the expected behavior --- ## Verification | Element | Expected Behavior | |---|---| | Nav menu items (Home, About, etc.) | Client-side nav, no page reload | | Logo "Portfolio" | Client-side nav to `/`, no reload | | Mobile menu items | Client-side nav + menu auto-closes | | "View Projects" button | Client-side nav to `/projects` | | "Contact Me" button | Client-side nav to `/contact` | | "Download Resume" button | Opens `/resume.pdf` in new tab | | "View All →" link | Client-side nav to `/projects` | | Project cards | Client-side nav to `/projects/:id` | | Social links (GitHub, LinkedIn) | Open in new tab (unchanged) | | Skip-to-content link | Jumps to `#main-content` on same page |