Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feature/410 gone #78706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: canary
Choose a base branch
from
Open

Feature/410 gone #78706

wants to merge 3 commits into from

Conversation

Sam7
Copy link

@Sam7 Sam7 commented Apr 30, 2025

Next.js 410 Gone Status Feature

This PR adds support for HTTP 410 Gone status in Next.js, providing developers with a way to indicate that content has been permanently removed. This is an important status code for SEO and user experience, as it differentiates between content that doesn't exist (404) and content that previously existed but has been deliberately removed (410).

Features

  • New gone() function for App Router
  • Support for gone: true in getServerSideProps and getStaticProps for Pages Router
  • Custom gone.js file convention similar to not-found.js
  • Automatic noindex meta tags for Gone pages
  • Clear error messages for conflicting return values

Implementation Details

This PR implements:

  1. App Router Support:

    • New gone() function in the next/navigation module
    • New gone.js file convention for customizing the 410 error page
    • Consistent behavior with other error handling patterns
  2. Pages Router Support:

    • Added support for returning { gone: true } from data fetching functions
    • Custom /410 page support similar to /404 page
  3. API Route Support:

    • Guidance for returning 410 status from API routes

Documentation

  • Added comprehensive documentation for the feature
  • Added examples for both App Router and Pages Router implementations
  • Added error documentation for invalid combinations (e.g., gone + redirect)

Tests

The PR includes:

  • Unit tests for the gone() function
  • Integration tests for Pages Router implementation
  • E2E tests for App Router implementation
  • Tests for browser navigation behavior
  • Error validation tests

Example Usage

App Router

import { gone } from 'next/navigation'

export default function PostPage({ params }) {
  // Check if content has been deliberately removed
  if (isDeleted(params.slug)) {
    gone() // Returns 410 Gone status
  }
  
  // Continue rendering content...
}

Pages Router

export async function getServerSideProps({ params }) {
  // Check if content has been deliberately removed
  if (isDeleted(params.id)) {
    return { gone: true } // Returns 410 Gone status
  }
  
  return { props: { /* ... */ } }
}

Example Project

An example project is included in gone-status demonstrating both App Router and Pages Router implementations of the feature.

Breaking Changes

None. This is a new feature with no changes to existing behavior.

Fixes #18684
Extends #73753

@ijjk ijjk added Documentation Related to Next.js' official documentation. examples Issue was opened via the examples template. tests type: next labels Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Related to Next.js' official documentation. examples Issue was opened via the examples template. tests type: next
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants