Added Recipe errorComponent.
This commit is contained in:
parent
8a5fd0a466
commit
68702595c5
@ -1,8 +1,10 @@
|
||||
import {
|
||||
createFileRoute,
|
||||
ErrorComponent,
|
||||
useLoaderData,
|
||||
useParams
|
||||
} from '@tanstack/react-router'
|
||||
import { ApiError } from '../../api/ApiError'
|
||||
import getRecipe from '../../api/getRecipe'
|
||||
import Recipe from '../../pages/recipe/Recipe'
|
||||
|
||||
@ -24,6 +26,16 @@ export const Route = createFileRoute('/recipes/$username/$slug')({
|
||||
})
|
||||
return <Recipe {...{ recipe }} />
|
||||
},
|
||||
errorComponent({ error }) {
|
||||
if (error instanceof ApiError) {
|
||||
return (
|
||||
<p>
|
||||
{error.status}: {error.message}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
return <ErrorComponent error={error} />
|
||||
},
|
||||
notFoundComponent() {
|
||||
const { username, slug } = useParams({
|
||||
from: '/recipes/$username/$slug'
|
||||
|
Loading…
Reference in New Issue
Block a user