ErrorPage.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { useRouteError, useNavigate } from 'react-router';
  2. import { AlertCircle, RotateCcw, Home } from 'lucide-react';
  3. import { Button } from '@/client/components/ui/button';
  4. import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/client/components/ui/card';
  5. import { Alert, AlertDescription, AlertTitle } from '@/client/components/ui/alert';
  6. export const ErrorPage = () => {
  7. const navigate = useNavigate();
  8. const error = useRouteError() as any;
  9. return (
  10. <div className="flex flex-col items-center justify-center min-h-screen bg-gradient-to-br from-slate-50 to-slate-100 dark:from-slate-900 dark:to-slate-800 p-4">
  11. <Card className="w-full max-w-md border-0 shadow-xl">
  12. <CardHeader className="bg-destructive/10">
  13. <CardTitle className="flex items-center space-x-2 text-destructive">
  14. <AlertCircle className="h-6 w-6" />
  15. <span>发生错误</span>
  16. </CardTitle>
  17. <CardDescription>
  18. 抱歉,页面加载时遇到了问题
  19. </CardDescription>
  20. </CardHeader>
  21. <CardContent className="space-y-4">
  22. <Alert variant="destructive">
  23. <AlertCircle className="h-4 w-4" />
  24. <AlertTitle>错误详情</AlertTitle>
  25. <AlertDescription>
  26. {error?.message || '未知错误'}
  27. </AlertDescription>
  28. </Alert>
  29. {error?.stack && (
  30. <div className="space-y-2">
  31. <h4 className="text-sm font-medium text-muted-foreground">技术信息</h4>
  32. <pre className="text-xs text-muted-foreground bg-muted/50 p-3 rounded-lg overflow-x-auto max-h-40">
  33. {error.stack}
  34. </pre>
  35. </div>
  36. )}
  37. </CardContent>
  38. <CardFooter className="flex gap-2">
  39. <Button
  40. onClick={() => navigate(0)}
  41. className="flex-1"
  42. variant="outline"
  43. >
  44. <RotateCcw className="h-4 w-4 mr-2" />
  45. 重新加载
  46. </Button>
  47. <Button
  48. onClick={() => navigate('/')}
  49. className="flex-1"
  50. >
  51. <Home className="h-4 w-4 mr-2" />
  52. 返回首页
  53. </Button>
  54. </CardFooter>
  55. </Card>
  56. </div>
  57. );
  58. };