I'd like to return a 404 error when a path parameter is invalid. I've tried doing this by throwing notFound from the params.parse function, but this just gives a generic 500 error. Is there a way to do this?
Example code (I want this to return 404 for /test/abc):
import { createFileRoute, notFound } from "@tanstack/react-router";
export const Route = createFileRoute("/test/$id")({
params: {
parse: ({ id }) => {
const parsedId = Number.parseInt(id, 10);
if (Number.isNaN(parsedId)) {
throw notFound();
}
return { id: parsedId };
},
},
component: () => {
const { id } = Route.useParams();
return <div>Test: {id}</div>;
},
});