Reputation: 843
Is it possible to configure two different 404 pages in Next.js — one for rendered pages and another one for API routes? I want the 404 page for API calls to return in JSON format while for all other pages in HTML.
Upvotes: 4
Views: 2328
Reputation: 2116
Yes it is possible just you have to create a wildcard page under the api page route. For example you can create a page page/api/[[...404]].js
. So, if no api route matches existing page it will show this page.
Upvotes: 9