2019-05-29 13:57:26 +02:00
# `<title>` should not be used in \_document.js's `<Head>`
2018-09-28 00:24:12 +02:00
#### Why This Error Occurred
Adding `<title>` in `pages/_document.js` will lead to unexpected results with `next/head` since `_document.js` is only rendered on the initial pre-render.
#### Possible Ways to Fix It
2018-12-03 23:04:18 +01:00
Set `<title>` in `pages/_app.js` instead:
2018-09-28 00:24:12 +02:00
```js
// pages/_app.js
2019-10-15 17:42:44 +02:00
import App from 'next/app'
2018-09-28 00:24:12 +02:00
import Head from 'next/head'
import React from 'react'
export default class MyApp extends App {
2019-05-29 13:57:26 +02:00
static async getInitialProps({ Component, ctx }) {
2018-09-28 00:24:12 +02:00
let pageProps = {}
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx)
}
2018-12-03 23:04:18 +01:00
return { pageProps }
2018-09-28 00:24:12 +02:00
}
2019-05-29 13:57:26 +02:00
render() {
2018-12-03 23:04:18 +01:00
const { Component, pageProps } = this.props
return (
2019-10-15 17:42:44 +02:00
< >
2018-12-03 23:04:18 +01:00
< Head >
< title > My new cool app< / title >
< / Head >
< Component { . . . pageProps } / >
2019-10-15 17:42:44 +02:00
< />
2018-12-03 23:04:18 +01:00
)
2018-09-28 00:24:12 +02:00
}
}
```
### Useful Links
- [The issue this was reported in: #4596 ](https://github.com/zeit/next.js/issues/4596 )