user2921009
user2921009

Reputation: 843

Next.js different 404 page for pages and for API calls

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

Answers (1)

udoyhasan
udoyhasan

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

Related Questions