How do I extract the title stored in the metadata
object within the layout.tsx
file?
page.tsx
:
import { Metadata } from 'next';
export const metadata: Metadata = {
title: 'Next.js',
};
export default function Page() {
return '...';
}
layout.tsx
:
import { ReactNode } from "react";
export default function Layout({children} : {children: ReactNode}) {
return <>
<h1>{/*metadata.title <-- what should be placed here?*/}</h1>
{children}
<>
}
To retrieve the title of the page, what should be inserted in place of metadata.title
?
This related question discusses a similar issue regarding retrieving the page title, but lacks any satisfactory solutions.