Next.js Discord

Discord Forum

Dynamic route 404 on production

Unanswered
Brown bear posted this in #help-forum
Open in Discord
Brown bearOP
Hi, I noticed a weird problem since v13.4.13. I get some 404 like https://mywebsite/_next/static/chunks/pages/profile/[id]-b8f14c78a702323f.js.
The first screenshot is the files, and in the [id].tsx file, there is:
import {useRouter} from 'next/router'

export default function Profile() {
    const router = useRouter()
    const id = router.query.id as string

    return (
        <div>
            <h1>Profile {id}</h1>
        </div>
    )
}

In this example, accessing to /profile/test won't work in prod, but for unknown reason it works in a dev env. Btw after testing, this problem does not happen at all when using next v13.4.12.
I don't know if it's because I'm new to next and I don't use the dynamic routes correctly or if this is a bug. Could someone explain me why is this happening and maybe how to fix it please?

1 Reply

Brown bearOP
I finally managed to solve my issue by serving static files using nginx directly. I was only doing a simple reverse proxy before, that's the problem I believe.