#Returning not found for invalid path params

5 messages · Page 1 of 1 (latest)

modern cove
#

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>;
        },
});
sick temple
#

are you using router or start?

modern cove
#

Start

sick temple
#

might be a bug. can you please create a github issue including a complete reproducer project?

modern cove