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
70b92e6b
Commit
70b92e6b
authored
Jan 16, 2017
by
Dan Zajdband
Committed by
Tim Neutkens
Jan 16, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added deprecation message when adding an extra anchor in behalf of the user. (#797)
parent
7cc554c6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
0 deletions
+14
-0
link.js
lib/link.js
+4
-0
utils.js
lib/utils.js
+10
-0
No files found.
lib/link.js
View file @
70b92e6b
import
{
resolve
}
from
'url'
import
{
resolve
}
from
'url'
import
React
,
{
Component
,
Children
,
PropTypes
}
from
'react'
import
React
,
{
Component
,
Children
,
PropTypes
}
from
'react'
import
Router
from
'./router'
import
Router
from
'./router'
import
{
warn
,
execOnce
}
from
'./utils'
export
default
class
Link
extends
Component
{
export
default
class
Link
extends
Component
{
constructor
(
props
)
{
constructor
(
props
)
{
...
@@ -69,6 +70,7 @@ export default class Link extends Component {
...
@@ -69,6 +70,7 @@ export default class Link extends Component {
if
(
isAnchor
)
{
if
(
isAnchor
)
{
return
React
.
cloneElement
(
child
,
props
)
return
React
.
cloneElement
(
child
,
props
)
}
else
{
}
else
{
warnLink
(
`Warning: Every Link must be the parent of an anchor, this pattern is deprecated. Please add an anchor inside the <Link>.`
)
return
<
a
{...
props
}
>
{
child
}
<
/a
>
return
<
a
{...
props
}
>
{
child
}
<
/a
>
}
}
})
})
...
@@ -82,3 +84,5 @@ export function isLocal (href) {
...
@@ -82,3 +84,5 @@ export function isLocal (href) {
return
!
/^
(
https
?
:
)?\/\/
/
.
test
(
href
)
||
return
!
/^
(
https
?
:
)?\/\/
/
.
test
(
href
)
||
origin
===
href
.
substr
(
0
,
origin
.
length
)
origin
===
href
.
substr
(
0
,
origin
.
length
)
}
}
const
warnLink
=
execOnce
(
warn
)
lib/utils.js
View file @
70b92e6b
...
@@ -4,6 +4,16 @@ export function warn (message) {
...
@@ -4,6 +4,16 @@ export function warn (message) {
}
}
}
}
export
function
execOnce
(
fn
)
{
let
used
=
false
return
(...
args
)
=>
{
if
(
!
used
)
{
used
=
true
fn
.
apply
(
this
,
args
)
}
}
}
export
function
deprecated
(
fn
,
message
)
{
export
function
deprecated
(
fn
,
message
)
{
if
(
process
.
env
.
NODE_ENV
===
'production'
)
return
fn
if
(
process
.
env
.
NODE_ENV
===
'production'
)
return
fn
...
...
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