"use client"; import { ArrowLeftIcon } from "lucide-react"; import Link from "next/link"; import { useRouter, useSearchParams } from "next/navigation"; const FROM_TO_PATH: Record = { portfolio: "/portfolio", "animal-studies": "/animal-studies", }; export function ContextBackButton() { const router = useRouter(); const sp = useSearchParams(); const from = sp.get("from") ?? ""; const target = FROM_TO_PATH[from]; if (!target) return null; return (
{ // If user has real history, prefer back; otherwise use link target. // (Prevents “dead end” if they opened single page directly in new tab.) if (window.history.length > 1) { e.preventDefault(); router.back(); } }} > Back
); }