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
540a86f0
Commit
540a86f0
authored
Feb 15, 2017
by
Naoyuki Kanezawa
Committed by
Tim Neutkens
Feb 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix prefetch url (#1154)
parent
141ab998
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
11 deletions
+22
-11
link.js
lib/link.js
+21
-10
prefetch.js
lib/prefetch.js
+1
-1
No files found.
lib/link.js
View file @
540a86f0
...
...
@@ -61,8 +61,28 @@ export default class Link extends Component {
})
}
prefetch
()
{
if
(
!
this
.
props
.
prefetch
)
return
if
(
typeof
window
===
'undefined'
)
return
// Prefetch the JSON page if asked (only in the client)
const
{
pathname
}
=
window
.
location
const
href
=
resolve
(
pathname
,
this
.
props
.
href
)
Router
.
prefetch
(
href
)
}
componentDidMount
()
{
this
.
prefetch
()
}
componentDidUpdate
(
prevProps
)
{
if
(
this
.
props
.
href
!==
prevProps
.
href
)
{
this
.
prefetch
()
}
}
render
()
{
let
{
children
,
prefetch
}
=
this
.
props
let
{
children
}
=
this
.
props
// Deprecated. Warning shown by propType check. If the childen provided is a string (<Link>example</Link>) we wrap it in an <a> tag
if
(
typeof
children
===
'string'
)
{
children
=
<
a
>
{
children
}
<
/a
>
...
...
@@ -79,15 +99,6 @@ export default class Link extends Component {
props
.
href
=
this
.
props
.
as
||
this
.
props
.
href
}
// Prefetch the JSON page if asked (only in the client)
if
(
prefetch
)
{
if
(
typeof
window
!==
'undefined'
)
{
const
{
pathname
}
=
window
.
location
const
href
=
resolve
(
pathname
,
props
.
href
)
Router
.
prefetch
(
href
)
}
}
return
React
.
cloneElement
(
child
,
props
)
}
}
...
...
lib/prefetch.js
View file @
540a86f0
...
...
@@ -25,7 +25,7 @@ export default class LinkPrefetch extends React.Component {
wantLinkPrefetch
()
const
props
=
{
...
this
.
props
,
prefetch
:
this
.
props
.
prefetch
===
false
?
this
.
props
.
prefetch
:
tru
e
prefetch
:
this
.
props
.
prefetch
!==
fals
e
}
return
(
<
Link
{...
props
}
/>
)
...
...
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