Next.js Discord

Discord Forum

Basic dynamic routing/route doesn't work

Unanswered
Black-capped Petrel posted this in #help-forum
Open in Discord
Black-capped PetrelOP
I am a beginner developer trying to NextJS to build a router to handle HTTP requests. I use JWT with bearer authentication. This is the link to my vercel deployed webpage. https://react-bug.vercel.app/api/login/admin_get_event/event_id
You can directly open it in a browser or send a GET request to it, and the expected outcome is a response with status code 500 and a JSON content {"error": "Unauthorized"} because there is no token. But now it redirects me to the home page, which is the same as https://react-bug.vercel.app/

The page file is in \app\api\login\admin_get_event[id]\route.js
It works totally fine on my local host.

My vercel configuration is as follows. Previously, the route didn't work at all, so I found the configuration on the web. I guess that my error is caused by this configuration, but I have no idea about how to fix it.
{
"rewrites": [
{"source": "/(.*)", "destination": "/"}
]
}

But for other non-dynamic routing, they all work fine. For example https://react-bug.vercel.app/api/get_home_events

This is my mini project so feel free to access my full code here https://github.com/AzikabanYuki/ReactBug

Huge thanks!

4 Replies

@Black-capped Petrel I am a beginner developer trying to NextJS to build a router to handle HTTP requests. I use JWT with bearer authentication. This is the link to my vercel deployed webpage. https://react-bug.vercel.app/api/login/admin_get_event/event_id You can directly open it in a browser or send a GET request to it, and the expected outcome is a response with status code 500 and a JSON content {"error": "Unauthorized"} because there is no token. But now it redirects me to the home page, which is the same as https://react-bug.vercel.app/ The page file is in \app\api\login\admin_get_event\[id]\route.js It works totally fine on my local host. My vercel configuration is as follows. Previously, the route didn't work at all, so I found the configuration on the web. I guess that my error is caused by this configuration, but I have no idea about how to fix it. { "rewrites": [ {"source": "/(.*)", "destination": "/"} ] } But for other non-dynamic routing, they all work fine. For example https://react-bug.vercel.app/api/get_home_events This is my mini project so feel free to access my full code here https://github.com/AzikabanYuki/ReactBug Huge thanks!
My vercel configuration is as follows. Previously, the route didn't work at all, so I found the configuration on the web. I guess that my error is caused by this configuration, but I have no idea about how to fix it.
{
"rewrites": [
{"source": "/(.*)", "destination": "/"}
]
}
remove it entirely. this maps every route to /
remove the vercel.json file
(btw to reproduce this locally i believe you can use vercel dev from the Vercel CLI, then you will also reproduce the bug locally)