When loading a blog post from the server, I have access to details like the title of the post. However, based on the app router migration guide, this information is located outside my page. How can I update it?
For more information, refer to the documentation: https://nextjs.org/docs/app/building-your-application/upgrading/app-router-migration#step-3-migrating-nexthead
async function onLoad (slug: string): Promise<PostInterface> {
const res = await API.get(`/posts?slug=${slug}`, {
headers: {
// ...
}
})
const post = res.data.data.posts[0]
if (!post) redirect('/404')
return post
}
export const metadata: Metadata = {
title: 'My Page Title That Needs To Be Replaced'
}
async function Page ({ params }: { params: { slug: string } }) {
const post = await onLoad(params.slug)
const { title } = post
// ... how do i change my document.title from server side?
// metadata.title = title will not work
}
export default Page