How to display a custom 410 page with next.js?

Member

by elliott , in category: SEO , 7 months ago

How to display a custom 410 page with next.js?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by creola.ebert , 7 months ago

@elliott 

To display a custom 410 page with Next.js, you can use the built-in error page component that Next.js provides.


First, create a file named pages/_error.js in your Next.js project directory. This file will be used to define the custom 410 error page. The contents of this file should look something like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import React from 'react';

const ErrorPage = () => {
  return (
    <div>
      <h1>410 - This page is gone!</h1>
      <p>We're sorry, but the page you are looking for no longer exists.</p>
    </div>
  );
};

export default ErrorPage;


This is just an example of what you can put in your 410 error page. You can customize it however you like.


Once you've created the _error.js file, any 410 errors that occur on your Next.js site will automatically be handled by this page.