Next.js Discord

Discord Forum

difference between API Routes and Route Handlers?

Answered
Chub mackerel posted this in #help-forum
Open in Discord
Chub mackerelOP
what does this mean-
Good to know: Route Handlers are only available inside the app directory. They are the equivalent of API Routes inside the pages directory meaning you do not need to use API Routes and Route Handlers together.

whats the need
Answered by joulev
api routes are in the pages router
route handlers are in the app router
that's it
View full answer

8 Replies

Answer
@joulev api routes are in the pages router route handlers are in the app router that's it
Chub mackerelOP
so just a different folder?
@Chub mackerel so just a different folder?
just like you go from pages/index.tsx to app/page.tsx, you go from pages/api/index.ts to app/api/route.ts
different routers different conventions
Chub mackerelOP
also another thing for route, it says "There cannot be a route.js file at the same route as page.js."
but when i put page.tsx and route.ts inside the same folder, it resolves to the route.ts
@joulev different routers different conventions
Chub mackerelOP
can i just forget about API routes?
@Chub mackerel can i just forget about API routes?
yeah well they do the same thing so you can just use the one you prefer
Chub mackerelOP
cool, thx