Next.js Discord

Discord Forum

Not found route not working in productiom

Unanswered
Honzosaurus_3.1415926535 posted this in #help-forum
Open in Discord
So I already asked like 5 times and never got an answer to my problem: I have a pretty new portfolio website that uses NextJS with the app dir and when I'm runnig it locally, my not-found.tsx works fine, but when I deploy the app on Vercel, it just completely stops working, which causes me to be able to visit any route and if it's a 404 then the home page will be displayed.

5 Replies

Original message was deleted
When I deploy my app, the not-found route (not-found.tsx) doesn't seem to work and on routes that should return a 404, the home page is displayed, which is weird, since the not found works normally when the app is ran locally
How do I get the not found route to work in production?
you might want to share code, file structure, ... See more info on how to ask a good question in https://nextjs-forum.com/post/1138338531983491154 and https://discord.com/channels/752553802359505017/752553802359505020/1108132433917919292
My bad; [this](https://github.com/Honzoraptor31415/PortfolioV2) is the whole codebase

And [this](https://github.com/Honzoraptor31415/PortfolioV2/blob/main/src/app/not-found.tsx) is my not found page:
import ErrorPage from "@/components/pages/Error"

export const metadata = {
  title: "Sorry, this page doesn't exist"
}

function NotFound() {
  return <ErrorPage code={404} message="Sorry, the page you're looking for could not be found." />
}

export default NotFound

I'm running Next 14.2.3
And [here](https://github.com/Honzoraptor31415/PortfolioV2/blob/main/src/components/pages/Error.tsx) I got the ErrorPage component:
"use client"

import Link from "next/link"

interface props {
  code: number
  message: string
}

function Error({ code, message }: props) {
  return (
    <header>
      <div className="error-page-dialog">
        <h1>Error {code}</h1>
        <p className="grey">{message}</p>
        {code === 404 && <Link href="/" className="text-link">Go to the home page</Link>}
      </div>
    </header>
  )
}

export default Error