Step 5: Page Titles
Part of the Next.js Essentials section of Coddy's React journey — lesson 43 of 47.
Challenge
EasyGive each dish its own tab title.
- In
app/menu/[slug]/page.jsx, exportasync function generateMetadata({ params }). - Await
paramsfor the slug, thenawait getDish(slug). - If there is no dish, return
{ title: 'Not on the menu' }. - Otherwise return the dish's
nameastitleand itsdescriptionasdescription.
Try it yourself
import Link from 'next/link';
import './globals.css';
export const metadata = {
title: {
default: 'Coddy Eats',
template: '%s | Coddy Eats',
},
};
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
<nav className="nav">
<Link className="brand" href="/">Coddy Eats</Link>
<Link id="nav-menu" href="/">Menu</Link>
<Link id="nav-desserts" href="/?category=dessert">Desserts</Link>
</nav>
<div className="container">
{children}
</div>
</body>
</html>
);
}