By default unregistered api routes fallback to below screen.
We can handle this by using Catch-all Segments in Next
In the /api
folder create a file [...rest].tsx
Give it a name of your choice. ( here rest refers to rest of the routes )
Now all unregistered routes can be handled in this file.
// [...rest].tsx
export default function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
res.status(404).json({ message: "Route not found" });
}
Top comments (0)