import { Component, Suspense, type ReactNode } from 'react'; import { Alert, Button, Spin } from 'antd'; import { PageLoadError } from '../lib/loadPage'; type Props = { location: string; children: ReactNode }; export class RouteBoundary extends Component { state = { location: this.props.location, failed: false }; static getDerivedStateFromProps(props: Props, state: { location: string }) { return props.location !== state.location ? { location: props.location, failed: false } : null; } static getDerivedStateFromError(error: unknown) { if (!(error instanceof PageLoadError)) throw error; return { failed: true }; } render() { if (this.state.failed) return ( window.location.reload()}>重新加载页面} /> ); return ( } > {this.props.children} ); } }