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
c8059b9f
Commit
c8059b9f
authored
Oct 31, 2017
by
Tim Neutkens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure linting passes
parent
53a2c5a7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
21 deletions
+20
-21
Link.js
examples/active-class-name/components/Link.js
+10
-10
Nav.js
examples/active-class-name/components/Nav.js
+6
-7
about.js
examples/active-class-name/pages/about.js
+2
-2
index.js
examples/active-class-name/pages/index.js
+2
-2
No files found.
examples/active-class-name/components/Link.js
View file @
c8059b9f
import
{
withRouter
}
from
'next/router'
;
import
Link
from
'next/link'
;
import
React
,
{
Children
}
from
'react'
;
import
{
withRouter
}
from
'next/router'
import
Link
from
'next/link'
import
React
,
{
Children
}
from
'react'
const
ActiveLink
=
({
router
,
children
,
...
props
})
=>
{
const
child
=
Children
.
only
(
children
)
;
const
child
=
Children
.
only
(
children
)
let
className
=
child
.
props
.
className
||
''
;
let
className
=
child
.
props
.
className
||
''
if
(
router
.
pathname
===
props
.
href
&&
props
.
activeClassName
)
{
className
=
`
${
className
}
${
props
.
activeClassName
}
`
.
trim
()
;
className
=
`
${
className
}
${
props
.
activeClassName
}
`
.
trim
()
}
delete
props
.
activeClassName
;
delete
props
.
activeClassName
return
<
Link
{...
props
}
>
{
React
.
cloneElement
(
child
,
{
className
})}
<
/Link>
;
}
;
return
<
Link
{...
props
}
>
{
React
.
cloneElement
(
child
,
{
className
})}
<
/Link
>
}
export
default
withRouter
(
ActiveLink
)
;
export
default
withRouter
(
ActiveLink
)
examples/active-class-name/components/Nav.js
View file @
c8059b9f
import
Link
from
'./Link'
;
import
Head
from
'next/head'
;
import
Link
from
'./Link'
export
default
()
=>
(
<
nav
>
...
...
@@ -17,15 +16,15 @@ export default () => (
<
ul
>
<
li
>
<
Link
activeClassName
=
"active"
href
=
"/"
>
<
a
className
=
"nav-link home-link"
>
Home
<
/a
>
<
Link
activeClassName
=
'active'
href
=
'/'
>
<
a
className
=
'nav-link home-link'
>
Home
<
/a
>
<
/Link
>
<
/li
>
<
li
>
<
Link
activeClassName
=
"active"
href
=
"/about"
>
<
a
className
=
"nav-link"
>
About
<
/a
>
<
Link
activeClassName
=
'active'
href
=
'/about'
>
<
a
className
=
'nav-link'
>
About
<
/a
>
<
/Link
>
<
/li
>
<
/ul
>
<
/nav
>
)
;
)
examples/active-class-name/pages/about.js
View file @
c8059b9f
import
Nav
from
'../components/Nav'
;
import
Nav
from
'../components/Nav'
export
default
()
=>
(
<
div
>
<
Nav
/>
<
p
>
Hello
,
I
'm About.js</p>
</div>
)
;
)
examples/active-class-name/pages/index.js
View file @
c8059b9f
import
Nav
from
'../components/Nav'
;
import
Nav
from
'../components/Nav'
export
default
()
=>
(
<
div
>
<
Nav
/>
<
p
>
Hello
,
I
'm the home page</p>
</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