ErrorPage.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import React from 'react';
  2. import { useRouteError, useNavigate } from 'react-router';
  3. import { Alert, AlertDescription, AlertTitle } from '@/client/components/ui/alert';
  4. import { Button } from '@/client/components/ui/button';
  5. import { AlertCircle } from 'lucide-react';
  6. export const ErrorPage = () => {
  7. const navigate = useNavigate();
  8. const error = useRouteError() as any;
  9. const errorMessage = error?.statusText || error?.message || '未知错误';
  10. return (
  11. <div className="flex flex-col items-center justify-center flex-grow p-4">
  12. <div className="max-w-3xl w-full">
  13. <h1 className="text-2xl font-bold mb-4">发生错误</h1>
  14. <Alert variant="destructive" className="mb-4">
  15. <AlertCircle className="h-4 w-4" />
  16. <AlertTitle>{error?.message || '未知错误'}</AlertTitle>
  17. <AlertDescription>
  18. {error?.stack ? (
  19. <pre className="text-xs overflow-auto p-2 bg-muted rounded mt-2">
  20. {error.stack}
  21. </pre>
  22. ) : null}
  23. </AlertDescription>
  24. </Alert>
  25. <div className="flex gap-4">
  26. <Button
  27. onClick={() => navigate(0)}
  28. >
  29. 重新加载
  30. </Button>
  31. <Button
  32. variant="outline"
  33. onClick={() => navigate('/admin')}
  34. >
  35. 返回首页
  36. </Button>
  37. </div>
  38. </div>
  39. </div>
  40. );
  41. };