ErrorPage.tsx 2.4 KB

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