How to add global meta tag for this Custom _document.js syntax #15222
-
I do have this known custom
I wanted to add a global meta tag |
Beta Was this translation helpful? Give feedback.
Answered by
jamesmosier
Jul 16, 2020
Replies: 1 comment
-
You could add it like this: import Document, { Html, Head, Main, NextScript } from 'next/document';
import { ServerStyleSheet } from 'styled-components';
export default class CustomDocument extends Document {
static async getInitialProps(ctx) {
const sheet = new ServerStyleSheet();
const originalRenderPage = ctx.renderPage;
try {
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: App => props => sheet.collectStyles(<App {...props} />),
});
const initialProps = await Document.getInitialProps(ctx);
return {
...initialProps,
styles: (
<>
{initialProps.styles}
{sheet.getStyleElement()}
</>
),
};
} finally {
sheet.seal();
}
}
render() {
return (
<Html lang="en">
<Head>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, shrink-to-fit=no, viewport-fit=cover" />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
bymoe
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could add it like this: