Home > front end >  NextJS custom 404 page not showing up
NextJS custom 404 page not showing up

Time:10-29

I have a custom pages/404.ts with the following content:

export default function NotFound() {
  return <h1>404 - Page Not Found</h1>
}

And I have another page that shows 404 when some organization is null:

import Error from 'next/error'

const Slug: NextPage<SlugProps> = ({ organization }) => {
  if (!organization) {
    return <Error statusCode={404} />
  }

  return <h1>{organization.name}</h1>
}

I want to NextJS show my custom 404 page, instead of, it showing the default

What I need to do to show my 404 page?

CodePudding user response:

You are reusing the built-in error page.

If you want to display your custom 404 in the dynamic route, just import your NotFound component and return that instead.

  • Related