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

**URL:** <https://forum.codewithmosh.com/t/the-convention-for-naming-api-endpoint-files-why-route-tsx/24066>\
**Category:** Next.js\
**Created:** [December 10, 2023, 9:00am UTC](https://forum.codewithmosh.com/t/the-convention-for-naming-api-endpoint-files-why-route-tsx/24066 "2023-12-10T09:00:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GAORI](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/gaori/32/6071_2.png) [@GAORI](https://forum.codewithmosh.com/u/GAORI)\
**Post date:** [December 10, 2023, 9:00am UTC](https://forum.codewithmosh.com/t/the-convention-for-naming-api-endpoint-files-why-route-tsx/24066/1 "2023-12-10T09:00:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![JerryHobby](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jerryhobby/32/5370_2.png) [@JerryHobby](https://forum.codewithmosh.com/u/JerryHobby)\
**Post date:** [December 10, 2023, 7:08pm UTC](https://forum.codewithmosh.com/t/the-convention-for-naming-api-endpoint-files-why-route-tsx/24066/2 "2023-12-10T19:08:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SAM](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sam/32/167_2.png) [@SAM](https://forum.codewithmosh.com/u/SAM)\
**Post date:** [December 11, 2023, 5:45am UTC](https://forum.codewithmosh.com/t/the-convention-for-naming-api-endpoint-files-why-route-tsx/24066/3 "2023-12-11T05:45:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![faisal](https://avatars.discourse-cdn.com/v4/letter/f/fbc32d/32.png) [@faisal](https://forum.codewithmosh.com/u/faisal)\
**Post date:** [October 12, 2026, 1:08am UTC](https://forum.codewithmosh.com/t/the-convention-for-naming-api-endpoint-files-why-route-tsx/24066/4 "2026-10-12T01:08:30Z")

</div>

“route.tsx” make me crazy !!!
