Reputation: 49
I want to stop redirecting to 404 page when page not found in my next.js app. I just want to show my 404 component without redirecting or changing URL.
Currently, next.js redirecting to 404/ URL.
Is there any ways?
Thanks!
Upvotes: 1
Views: 5264
Reputation: 65
The Next.js framework has built-in ways for handling 404, 500, and other errors that may occur on your website. But to add custom layout and styling to those pages, you'll need to create both a /pages/404.js
and /pages/_error.js
file.
When one of those errors occur, Next.js will render that page instead of the default page it would otherwise automatically generate.
The /pages/404.js
file will handle all 404 related errors. And the /pages/_error.js
file will handle 500 type errors.
here's official documentation customizing 404
Upvotes: 1