ErrorPage.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import React from 'react';
  2. import { useRouteError } from 'react-router';
  3. import { Alert, Button } from 'antd';
  4. import { useTheme } from '../hooks_sys.tsx';
  5. export const ErrorPage = () => {
  6. const { isDark } = useTheme();
  7. const error = useRouteError() as any;
  8. const errorMessage = error?.statusText || error?.message || '未知错误';
  9. return (
  10. <div className="flex flex-col items-center justify-center min-h-screen p-4"
  11. style={{ color: isDark ? '#fff' : 'inherit' }}
  12. >
  13. <div className="max-w-3xl w-full">
  14. <h1 className="text-2xl font-bold mb-4">发生错误</h1>
  15. <Alert
  16. type="error"
  17. message={error?.message || '未知错误'}
  18. description={
  19. error?.stack ? (
  20. <pre className="text-xs overflow-auto p-2 bg-gray-100 dark:bg-gray-800 rounded">
  21. {error.stack}
  22. </pre>
  23. ) : null
  24. }
  25. className="mb-4"
  26. />
  27. <div className="flex gap-4">
  28. <Button
  29. type="primary"
  30. onClick={() => window.location.reload()}
  31. >
  32. 重新加载
  33. </Button>
  34. <Button
  35. onClick={() => window.location.href = '/admin'}
  36. >
  37. 返回首页
  38. </Button>
  39. </div>
  40. </div>
  41. </div>
  42. );
  43. };