ErrorPage.tsx 1.3 KB

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