Overview

When creating an API like </api/_search>, I looked into how to create URL segments starting with underscores, so this is a personal note for future reference.

Method

The information was found in the following documentation.

https://nextjs.org/docs/app/building-your-application/routing/colocation#:~:text=js file conventions.-,Good to know,-While not a

The key point is:

To create URL segments that start with an underscore, prefix the folder name with %5F (the URL-encoded form of an underscore). Example: %5FfolderName.

I was able to resolve this by creating the file as /api/%5Fsearch/route.ts.

Summary

I hope this serves as a useful reference.