T
TanStack2y ago
genetic-orange

How to define a 404 or not found page in SSR file based ? (v1.0.0)

Hey guys and first thing Merry Christmas ! 🎄 I just updated to v1.0.0 and I want to implement a 404 route in an SSR file based project (same setup as the demo on the documentation). Do you have any information in the documentation about that or a code snippet somewhere please ? Just creating a file name not_found.tsx is not doing the trick. I saw a discord post speaking about NotFoundError() but I don't have any clue. My goal is to throw a 404 from a loader if fetched ressource doesn't exist:
loader: async ({ params }) => {
const post = await trpcClient.post.getPostById.query(params.postId)
if(something)){
throw redirect({ to: '/custom-route-that-handles-this' })
}
if(somethingElse){
throw redirect({ to: `/404` });
//or throw new NotFoundError();
}
return post
}
loader: async ({ params }) => {
const post = await trpcClient.post.getPostById.query(params.postId)
if(something)){
throw redirect({ to: '/custom-route-that-handles-this' })
}
if(somethingElse){
throw redirect({ to: `/404` });
//or throw new NotFoundError();
}
return post
}
Thx ! ✌️
1 Reply
genetic-orange
genetic-orangeOP2y ago
Hi, no one has an example on how to do it ? Should I create a github issue ?

Did you find this page helpful?