-
Notifications
You must be signed in to change notification settings - Fork 27.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix first render of with-react-helmet example (#6235)
- Loading branch information
1 parent
63c25a9
commit b05df70
Showing
4 changed files
with
44 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react' | ||
import App, { Container } from 'next/app' | ||
import Helmet from 'react-helmet' | ||
|
||
export default class MyApp extends App { | ||
static async getInitialProps ({ Component, ctx }) { | ||
let pageProps = {} | ||
|
||
if (Component.getInitialProps) { | ||
pageProps = await Component.getInitialProps(ctx) | ||
} | ||
|
||
return { pageProps } | ||
} | ||
|
||
render () { | ||
const { Component, pageProps } = this.props | ||
|
||
return ( | ||
<Container> | ||
<Helmet | ||
htmlAttributes={{ lang: 'en' }} | ||
title='Hello next.js!' | ||
meta={[ | ||
{ name: 'viewport', content: 'width=device-width, initial-scale=1' }, | ||
{ property: 'og:title', content: 'Hello next.js!' } | ||
]} | ||
/> | ||
<Component {...pageProps} /> | ||
</Container> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,14 @@ | ||
import React from 'react' | ||
import Helmet from 'react-helmet' | ||
|
||
export default class About extends React.Component { | ||
static async getInitialProps ({ req }) { | ||
if (req) { | ||
Helmet.renderStatic() | ||
} | ||
return { title: 'About' } | ||
} | ||
|
||
render () { | ||
const { title } = this.props | ||
return ( | ||
<div> | ||
<Helmet | ||
title={`${title} | Hello next.js!`} | ||
meta={[{ property: 'og:title', content: title }]} | ||
/> | ||
About the World | ||
</div> | ||
) | ||
} | ||
export default function About () { | ||
return ( | ||
<div> | ||
<Helmet | ||
title='About | Hello next.js!' | ||
meta={[{ property: 'og:title', content: 'About' }]} | ||
/> | ||
About the World | ||
</div> | ||
) | ||
} |