Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): Typesafe metadata object #52252

Merged
merged 14 commits into from Jul 10, 2023
Merged
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 13 additions & 9 deletions docs/02-app/02-api-reference/04-functions/generate-metadata.mdx
Expand Up @@ -177,9 +177,8 @@ export const metadata: Metadata = {
```

```jsx filename="app/layout.js" switcher
import { Metadata } from 'next'

export const metadata: Metadata = {
export const metadata = {
title: {
default: '...',
template: '...',
Expand All @@ -193,15 +192,19 @@ export const metadata: Metadata = {
`title.default` can be used to provide a **fallback title** to child route segments that don't define a `title`.

```tsx filename="app/layout.tsx"
export const metadata = {
import type { Metadata } from 'next'

export const metadata: Metadata = {
carlos-menezes marked this conversation as resolved.
Show resolved Hide resolved
title: {
default: 'Acme',
},
}
```

```tsx filename="app/about/page.tsx"
export const metadata = {}
import type { Metadata } from 'next'

export const metadata: Metadata = {}
carlos-menezes marked this conversation as resolved.
Show resolved Hide resolved

// Output: <title>Acme</title>
```
Expand All @@ -222,9 +225,9 @@ export const metadata: Metadata = {
```

```jsx filename="app/layout.js" switcher
import { Metadata } from 'next'
import type { Metadata } from 'next'
styfle marked this conversation as resolved.
Show resolved Hide resolved

export const metadata: Metadata = {
export const metadata = {
title: {
template: '%s | Acme',
default: 'Acme', // a default is required when creating a template
Expand All @@ -243,9 +246,8 @@ export const metadata: Metadata = {
```

```jsx filename="app/about/page.js" switcher
import { Metadata } from 'next'

export const metadata: Metadata = {
export const metadata = {
title: 'About',
}

Expand Down Expand Up @@ -520,7 +522,9 @@ export const metadata = {
### `robots`

```tsx
export const metadata = {
import type { Metadata } from 'next'

export const metadata: Metadata = {
carlos-menezes marked this conversation as resolved.
Show resolved Hide resolved
robots: {
index: false,
follow: true,
Expand Down