-
Notifications
You must be signed in to change notification settings - Fork 26.1k
/
_document.tsx
46 lines (42 loc) · 938 Bytes
/
_document.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import Document, {
Html,
Head,
Main,
NextScript,
DocumentContext,
} from 'next/document';
interface Props {
locale: string;
lang: string;
nonce: string;
}
class MyDocument extends Document<Props> {
static async getInitialProps(ctx: DocumentContext) {
const {req} = ctx;
const initialProps = await Document.getInitialProps(ctx);
return {
...initialProps,
locale: (req as any).locale || 'en',
lang: ((req as any).locale || 'en').split('-')[0],
nonce: (req as any).nonce,
};
}
render() {
return (
<Html lang={this.props.lang}>
<Head />
<body>
<script
nonce={this.props.nonce}
dangerouslySetInnerHTML={{
__html: `window.LOCALE="${this.props.locale}"`,
}}
></script>
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default MyDocument;