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
c106a1d0
Commit
c106a1d0
authored
Feb 09, 2017
by
Tim Neutkens
Committed by
Arunoda Susiripala
Feb 09, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using router example improvements (#1034)
parent
4534c559
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
29 deletions
+32
-29
Header.js
examples/using-router/components/Header.js
+18
-18
error.js
examples/using-router/pages/error.js
+14
-11
No files found.
examples/using-router/components/Header.js
View file @
c106a1d0
...
@@ -2,30 +2,30 @@ import Router from 'next/router'
...
@@ -2,30 +2,30 @@ import Router from 'next/router'
export
default
()
=>
(
export
default
()
=>
(
<
div
>
<
div
>
<
Link
href
=
'/'
>
<
a
>
Home
<
/a>
</
Link
>
<
Link
href
=
'/'
>
Home
<
/Link
>
<
Link
href
=
'/about'
>
<
a
>
About
<
/a>
</
Link
>
<
Link
href
=
'/about'
>
About
<
/Link
>
<
Link
href
=
'/error'
>
<
a
>
Error
<
/a>
</
Link
>
<
Link
href
=
'/error'
>
Error
<
/Link
>
<
/div
>
<
/div
>
)
)
// typically you want to use `next/link` for this usecase
// typically you want to use `next/link` for this usecase
// but this example shows how you can also access the router
// but this example shows how you can also access the router
// and use it manually
// and use it manually
const
Link
=
({
children
,
href
})
=>
(
<
a
href
=
'#'
style
=
{
styles
.
a
}
onClick
=
{(
e
)
=>
{
e
.
preventDefault
()
Router
.
push
(
href
)
}}
>
{
children
}
<
/a
>
)
const
styles
=
{
function
onClickHandler
(
href
)
{
a
:
{
return
(
e
)
=>
{
marginRight
:
10
e
.
preventDefault
()
Router
.
push
(
href
)
}
}
}
}
const
Link
=
({
children
,
href
})
=>
(
<
a
href
=
'#'
onClick
=
{
onClickHandler
(
href
)}
>
{
children
}
<
style
jsx
>
{
`
a {
margin-right: 10px;
}
`
}
<
/style
>
<
/a
>
)
examples/using-router/pages/error.js
View file @
c106a1d0
import
React
from
'react'
import
{
Component
}
from
'react'
import
Header
from
'../components/Header'
import
Header
from
'../components/Header'
import
Router
from
'next/router'
import
Router
from
'next/router'
const
ErrorPage
=
({
aa
})
=>
(
export
default
class
extends
Component
{
<
div
>
static
getInitialProps
()
{
<
Header
/>
console
.
log
(
Router
.
pathname
)
<
p
>
This
should
not
be
rendered
via
SSR
<
/p
>
return
{}
<
/div
>
}
)
ErrorPage
.
getInitialProps
=
()
=>
{
render
()
{
console
.
log
(
Router
.
pathname
)
return
(
<
div
>
<
Header
/>
<
p
>
This
should
not
be
rendered
via
SSR
<
/p
>
<
/div
>
)
}
}
}
export
default
ErrorPage
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