Blame view

src/routes/error.tsx 955 Bytes
7619887f   张志伟   🐹 feat(*): 增加缺省页面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  import { Empty, helper, Button } from '@feewee/h5app-common';
  import { useNavigate, useRouteError } from '@modern-js/runtime/router';
  import { useCallback, useEffect } from 'react';
  
  function ErrorBoundary() {
    const error: any = useRouteError();
    const navigate = useNavigate();
  
    const lisFn = useCallback((e: any) => {
      if ('hardwareBackPress' == e.data) {
        helper.checkBack(() => navigate(-1));
      }
    }, []);
  
    useEffect(() => {
      window.document.addEventListener('message', lisFn);
  
      return () => {
        window.document.removeEventListener('message', lisFn);
      };
    }, []);
  
    return (
      <Empty type="timeOut" className="pt-8 max-w-screen-md mx-auto" description={error?.message}>
        <div className="mt-8 mx-auto w-4/6">
          <Button type="primary" block size="large" onClick={() => helper.checkBack(() => navigate(-1))}>
            返回
          </Button>
        </div>
      </Empty>
    );
  }
  export default ErrorBoundary;