Skip to content

useRouteError return type #9628

Closed Answered by PhiltasticGuy
j-machuca asked this question in Q&A
Discussion options

You must be logged in to vote

Hi,

I don't have an answer for your question per se, but you could look into using the isRouteErrorResponse function from react-router-dom.

Based on isRouteErrorResponse's documentation, you could write something like this:

import { isRouteErrorResponse, useRouteError } from "react-router-dom";

export function ErrorPage() {
  const error = useRouteError();

  if (isRouteErrorResponse(error)) {
    if (error.status === 401) {
      // ...
    }
    else if (error.status === 404) {
      // ...
    }

    return (
      <div id="error-page">
        <h1>Oops! {error.status}</h1>
        <p>{error.statusText}</p>
        {error.data?.message && (
          <p>
            <i>{error.data.mes…

Replies: 4 comments 7 replies

Comment options

You must be logged in to vote
4 replies
@OkuruchiDan
Comment options

@azamat-reactjs
Comment options

@aasspaassp
Comment options

@ckhackshaw
Comment options

Answer selected by j-machuca
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@PavelMikuMr
Comment options

Comment options

You must be logged in to vote
2 replies
@sanghunjlee
Comment options

@qadzek
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet