_document.js 814 B

123456789101112131415161718192021222324252627282930
  1. import React from 'react';
  2. import Document, { Head, Main, NextScript } from 'next/document';
  3. import { ServerStyleSheet } from 'styled-components';
  4. import { i18n } from '../i18n';
  5. class MyDocument extends Document {
  6. static getInitialProps({ renderPage }) {
  7. const sheet = new ServerStyleSheet();
  8. const page = renderPage(App => props => sheet.collectStyles(<App {...props} />));
  9. const styleTags = sheet.getStyleElement();
  10. return { ...page, styleTags };
  11. }
  12. render() {
  13. return (
  14. <html lang={i18n.language}>
  15. <Head>
  16. <link rel="shortcut icon" type="image/x-icon" href="/static/favicon.ico" />
  17. {this.props.styleTags}
  18. </Head>
  19. <body>
  20. <Main />
  21. <NextScript />
  22. </body>
  23. </html>
  24. );
  25. }
  26. }
  27. export default MyDocument;