_document.js 831 B

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