In Next.js I’m getting a 404 error when I try to send a get request to a static route handler inside a dynamic one

  Kiến thức lập trình

I’m using thunder client and although the dynamic route is working fine, when I send a get request to the successor route it throws a 404 not found error, I know this means that the request can’t reach the route.

The files hierarchy looks like this:

  • app/api/firebase/collection/[collectionName]/route.ts
  • app/api/firebase/collection/[collectionName]/products/route.ts
    the request for the dynamic route works fine
    the request for the successor static route doesn’t work

this code is the same for both [collectionName] and products code

export async function GET() {
  return NextResponse.json({ message: "done" });

The code should fetch collections and products from the database but I’ve simplified it to that level to tackle the issue and still can’t identify the problem. maybe is it prohibited in restAPI to put a static route inside a dynamic route I don’t know…

I and appreciate any help, thanks in advance. 🙂

New contributor

Hossam Adel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.