Skip to contents

Usage

isRouteErrorResponse()

Value

A JS expression evaluating to the isRouteErrorResponse function reference.

Details

Returns a JS reference to the isRouteErrorResponse type guard. Use it inside an errorElement render callback to branch on whether the error came from a thrown Response (e.g. throw new Response(..., { status: 404 })) or from arbitrary code. Pair with useRouteError.

Calling isRouteErrorResponse() from R returns a JS expression that evaluates, in the browser, to the upstream isRouteErrorResponse function. Interpolate it inside the render string of useRouteError() as shown below.

For convenience, the same function is also reachable inside any user-authored JS string as window.jsmodule['@/reactRouter'].helpers.isRouteErrorResponse.

Examples

if (FALSE) { # \dontrun{
useRouteError(render = JS(paste0(
  "e => ", isRouteErrorResponse(),
  "(e) ? <p>HTTP {e.status}</p> : <p>Unknown error</p>"
)))
} # }