The convention for naming api endpoint files, why ‘route.tsx?

I think that the api endpoint doesn’t related to react, so it’s right to use ‘route.ts’. What is the reason to use ‘route.tsx’ instead?

Next.JS uses some predefined filenames for various things so that it just knows where to find those things. This standard encourages a consistent standard and eliminates the need to define what files do what – this helps the compiler.

Predefined filenames in Next.JS include:

page.[js, jsx, ts, tsx]
route.[js, jsx, ts, tsx]
layout.[js, jsx, ts, tsx]
error.[js, jsx, ts, tsx]
loading.[js, jsx, ts, tsx]
not-found.[js, jsx, ts, tsx]
template.[js, jsx, ts, tsx]

There are a lot of other special filenames as well. It’s just the nature of the beast.

Jerry

1 Like

There’s no reason. I think Mosh did that inadvertently and didn’t notice it because it worked.

1 Like