Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
b05df708
Commit
b05df708
authored
Feb 10, 2019
by
Fredrik Höglund
Committed by
Tim Neutkens
Feb 10, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix first render of with-react-helmet example (#6235)
parent
63c25a9c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
34 deletions
+44
-34
README.md
examples/with-react-helmet/README.md
+1
-0
_app.js
examples/with-react-helmet/pages/_app.js
+33
-0
_document.js
examples/with-react-helmet/pages/_document.js
+0
-14
about.js
examples/with-react-helmet/pages/about.js
+10
-20
No files found.
examples/with-react-helmet/README.md
View file @
b05df708
...
@@ -46,4 +46,5 @@ now
...
@@ -46,4 +46,5 @@ now
This an minimalistic example of how to combine next.js and
[
react-helmet
](
https://github.com/nfl/react-helmet
)
.
This an minimalistic example of how to combine next.js and
[
react-helmet
](
https://github.com/nfl/react-helmet
)
.
The title of the page shall be changed to "Hello next.js!"
The title of the page shall be changed to "Hello next.js!"
If you go to the page
`/about`
, the title will be overridden to "About | Hello next.js!"
The rest is all up to you.
The rest is all up to you.
examples/with-react-helmet/pages/_app.js
0 → 100644
View file @
b05df708
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
>
)
}
}
examples/with-react-helmet/pages/_document.js
View file @
b05df708
...
@@ -26,24 +26,10 @@ export default class extends Document {
...
@@ -26,24 +26,10 @@ export default class extends Document {
.
map
(
el
=>
this
.
props
.
helmet
[
el
].
toComponent
())
.
map
(
el
=>
this
.
props
.
helmet
[
el
].
toComponent
())
}
}
get
helmetJsx
()
{
return
(
<
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!'
}
]}
/
>
)
}
render
()
{
render
()
{
return
(
return
(
<
html
{...
this
.
helmetHtmlAttrComponents
}
>
<
html
{...
this
.
helmetHtmlAttrComponents
}
>
<
Head
>
<
Head
>
{
this
.
helmetJsx
}
{
this
.
helmetHeadComponents
}
{
this
.
helmetHeadComponents
}
<
/Head
>
<
/Head
>
<
body
{...
this
.
helmetBodyAttrComponents
}
>
<
body
{...
this
.
helmetBodyAttrComponents
}
>
...
...
examples/with-react-helmet/pages/about.js
View file @
b05df708
import
React
from
'react'
import
React
from
'react'
import
Helmet
from
'react-helmet'
import
Helmet
from
'react-helmet'
export
default
class
About
extends
React
.
Component
{
export
default
function
About
()
{
static
async
getInitialProps
({
req
})
{
return
(
if
(
req
)
{
<
div
>
Helmet
.
renderStatic
()
<
Helmet
}
title
=
'About | Hello next.js!'
return
{
title
:
'About'
}
meta
=
{[{
property
:
'og:title'
,
content
:
'About'
}]}
}
/
>
About
the
World
render
()
{
<
/div
>
const
{
title
}
=
this
.
props
)
return
(
<
div
>
<
Helmet
title
=
{
`
${
title
}
| Hello next.js!`
}
meta
=
{[{
property
:
'og:title'
,
content
:
title
}]}
/
>
About
the
World
<
/div
>
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment