AwsLinker/app/components/news/BackButton.tsx
2025-09-16 17:19:58 +08:00

36 lines
908 B
TypeScript

'use client';
import { ArrowLeft } from 'lucide-react';
import { Button } from '@/app/components/ui/button';
import { useRouter } from 'next/navigation';
import Link from 'next/link';
interface BackButtonProps {
text: string;
href: string;
}
export default function BackButton({ text, href }: BackButtonProps) {
const router = useRouter();
const handleBack = () => {
// 如果浏览器有历史记录,则返回上一页
if (typeof window !== 'undefined' && window.history.length > 1) {
router.back();
} else {
// 否则导航到指定页面
router.push(href);
}
};
return (
<Button
variant="ghost"
className="mb-6 hover:bg-blue-50"
onClick={handleBack}
>
<ArrowLeft className="mr-2" size={20} />
{text}
</Button>
);
}