import { isRouteErrorResponse, Link, useRouteError } from 'react-router-dom' import { isPreloadError } from './preloadErrors' export function RouteError() { const routeError = useRouteError() const isNotFound = isRouteErrorResponse(routeError) && routeError.status === 404 const preloadFailed = isPreloadError(routeError) let heading = 'This page could not be opened' if (isNotFound) { heading = 'That route went missing' } else if (preloadFailed) { heading = 'This page needs a refresh' } let message = 'This page could not be opened.' if (preloadFailed) { message = 'Part of this page could not be downloaded. Refresh the page to try again.' } else if (isRouteErrorResponse(routeError)) { message = routeError.statusText } else if (routeError instanceof Error) { message = routeError.message } return (
{isNotFound ? 'Page not found — SkyTrace' : 'Page unavailable — SkyTrace'}

{heading}

{message}

{!isNotFound && ( )} Back to search
) }