Next.js Discord

Discord Forum

API route handler, change /api route

Answered
Himalayan posted this in #help-forum
Open in Discord
HimalayanOP
Hey all

Is there an easy way to change the root path being used by the api route handler? for example /api -> /next-api. I did not try a rewrite yet, might also be an option.
Answered by joulev
app router: yes. just make app/next-api/... instead of app/api/...

pages router: no. you must redirect/rewrite.
View full answer

5 Replies

@Himalayan Hey all Is there an easy way to change the root path being used by the api route handler? for example /api -> /next-api. I did not try a rewrite yet, might also be an option.
app router: yes. just make app/next-api/... instead of app/api/...

pages router: no. you must redirect/rewrite.
Answer
HimalayanOP
ah haha stupid question haha it's just like other routes I assume it can be whatever path I want :p
I was thinking it was fixed for some reason :p
Serbian Hound
@Himalayan i was going to ask the exact same question so thank you, i thought it was fixed too
yeah it is not fixed, in the app router you have full freedom over the pathname