mirror of
https://github.com/zhigang1992/react.git
synced 2026-01-31 09:08:41 +08:00
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import Document, { Html, Head, Main, NextScript } from 'next/document'
|
|
import flush from 'styled-jsx/server'
|
|
import { DocumentContext, DocumentInitialProps } from 'next/dist/next-server/lib/utils'
|
|
|
|
class MyDocument extends Document {
|
|
static async getInitialProps (ctx: DocumentContext): Promise<DocumentInitialProps> {
|
|
const initialProps = await Document.getInitialProps(ctx)
|
|
|
|
return {
|
|
...initialProps,
|
|
styles: (
|
|
<>
|
|
{initialProps.styles}
|
|
{flush()}
|
|
</>
|
|
)
|
|
}
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<Html>
|
|
<Head />
|
|
<body>
|
|
<Main />
|
|
<NextScript />
|
|
<script async src={`https://www.googletagmanager.com/gtag/js?id=UA-110371817-12`} />
|
|
<script
|
|
async
|
|
dangerouslySetInnerHTML={{
|
|
__html: `
|
|
window.dataLayer = window.dataLayer || [];
|
|
function gtag(){dataLayer.push(arguments);}
|
|
gtag('js', new Date());
|
|
gtag('config', 'UA-110371817-12');
|
|
`
|
|
}}
|
|
/>
|
|
</body>
|
|
</Html>
|
|
)
|
|
}
|
|
}
|
|
|
|
export default MyDocument
|