Recommended way to return a 410 Gone status from page.tsx in Next.js 16 #86345
Replies: 2 comments 1 reply
-
|
create simple new page, and rewrite that page with 410 status code export async function middleware(request) {
const path = request.nextUrl.pathname; // ex:. /post/foo-bar
// check incoming slug etc. here
// then do rewrite
let goneRewrite = NextResponse.rewrite(new URL(`/gone`, request.url), {
status: 410,
});
goneRewrite.headers.set('x-middleware-cache', 'no-cache');
return goneRewrite;
} |
Beta Was this translation helpful? Give feedback.
-
|
I’ve come up with this solution for now, until Next.js provides official support for setting a 410 status code directly in page.tsx. I'm using a custom
import { NextResponse } from "next/server";
export async function GET() {
const htmlContent = `
<!DOCTYPE html>
<html>
<head>
<title>410 - Content Gone</title>
<meta name="robots" content="noindex">
<style>
body { font-family: sans-serif; text-align: center; padding: 50px; }
</style>
</head>
<body>
<h1>410 - Gone</h1>
<p>This content has been permanently deleted.</p>
<a href="/">Return Home</a>
</body>
</html>
`;
return new NextResponse(htmlContent, {
status: 410,
headers: { "Content-Type": "text/html`" },
});
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I’m looking for guidance on the recommended approach for returning a
410 Gone statusin Next.js using the App Router.I'm using Next.js 16 and I need to return a 410 status in
page.tsx.I have gone through this discussion, but it doesn’t provide a clear solution.
The related PR is still not merged, so until then, is there any workaround for this?
What is the best way to handle this scenario?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions