I want to redirect users from one of my pages. I used to do it with redirect metatag. However, I don't find similar options in metadata
api in Next.js 13 appRouter
.
Asked
Active
Viewed 79 times
1

Drew Reese
- 165,259
- 14
- 153
- 181

Mayank Kumar Chaudhari
- 16,027
- 10
- 55
- 122
1 Answers
1
redirect metadata does not have any built-in support yet.
Checkout - https://nextjs.org/docs/app/api-reference/functions/generate-metadata#unsupported-metadata
We can use appropriate HTTP Headers via redirect(), Middleware, Security Headers
import { redirect } from 'next/navigation'
async function fetchTeam(id) {
const res = await fetch('https://...')
if (!res.ok) return undefined
return res.json()
}
export default async function Profile({ params }) {
const team = await fetchTeam(params.id)
if (!team) {
redirect('/login')
}
// ...
}

Mayank Kumar Chaudhari
- 16,027
- 10
- 55
- 122