Basic 404 not found for Recipe.
This commit is contained in:
parent
fa7d104bd2
commit
201ddb6656
@ -1,3 +1,4 @@
|
|||||||
|
import { notFound } from '@tanstack/react-router'
|
||||||
import { ApiError } from './ApiError'
|
import { ApiError } from './ApiError'
|
||||||
import FullRecipeView, { RawFullRecipeView } from './types/FullRecipeView'
|
import FullRecipeView, { RawFullRecipeView } from './types/FullRecipeView'
|
||||||
import { toImageView } from './types/ImageView'
|
import { toImageView } from './types/ImageView'
|
||||||
@ -45,6 +46,8 @@ const getRecipe = async (
|
|||||||
viewerCount,
|
viewerCount,
|
||||||
mainImage: toImageView(rawMainImage)
|
mainImage: toImageView(rawMainImage)
|
||||||
}
|
}
|
||||||
|
} else if (response.status === 404) {
|
||||||
|
throw notFound()
|
||||||
} else {
|
} else {
|
||||||
throw new ApiError(response.status, response.statusText)
|
throw new ApiError(response.status, response.statusText)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
import { createFileRoute, useLoaderData } from '@tanstack/react-router'
|
import {
|
||||||
|
createFileRoute,
|
||||||
|
useLoaderData,
|
||||||
|
useParams
|
||||||
|
} from '@tanstack/react-router'
|
||||||
import getRecipe from '../../api/getRecipe'
|
import getRecipe from '../../api/getRecipe'
|
||||||
import Recipe from '../../pages/recipe/Recipe'
|
import Recipe from '../../pages/recipe/Recipe'
|
||||||
|
|
||||||
@ -9,10 +13,20 @@ export const Route = createFileRoute('/recipes/$username/$slug')({
|
|||||||
queryFn: () =>
|
queryFn: () =>
|
||||||
getRecipe(context.auth.token, params.username, params.slug)
|
getRecipe(context.auth.token, params.username, params.slug)
|
||||||
}),
|
}),
|
||||||
component: () => {
|
component() {
|
||||||
const recipe = useLoaderData({
|
const recipe = useLoaderData({
|
||||||
from: '/recipes/$username/$slug'
|
from: '/recipes/$username/$slug'
|
||||||
})
|
})
|
||||||
return <Recipe {...{ recipe }} />
|
return <Recipe {...{ recipe }} />
|
||||||
|
},
|
||||||
|
notFoundComponent() {
|
||||||
|
const { username, slug } = useParams({
|
||||||
|
from: '/recipes/$username/$slug'
|
||||||
|
})
|
||||||
|
return (
|
||||||
|
<p>
|
||||||
|
404: Could not find a Recipe for {username}/{slug}
|
||||||
|
</p>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user