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