Deviopath › Next.js

Title Template

Easy · Metadata

In a layout you can export metadata with title: { template: "%s | Shop", default: "Shop" }. Pages below that layout then only set their own title (like "Cart"), and Next.js puts it into the template where %s is, giving "Cart | Shop". A page without a title gets the default.

Write buildTitle(template, title, defaultTitle):

- If title is a non-empty string, return template with %s replaced by title.

- Otherwise (undefined or ""), return defaultTitle.

Next: Active Nav Link