Sahil Geek
Sahil Geek

Reputation: 49

How to Stop Redirecting to 404 page When page Not found in Next.js

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

Answers (2)

Lasha Markhvaidze
Lasha Markhvaidze

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

Ajay Raja
Ajay Raja

Reputation: 376

You can create custom 404 page in NextJS with creating file in

/pages/404.js

You can create page for 404 error. For more Details click here

Upvotes: 0

Related Questions