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
d382e4db
Commit
d382e4db
authored
Feb 15, 2017
by
Eric Zingeler
Committed by
Arunoda Susiripala
Feb 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replace location.origin usage with new utils/getLocationOrigin (#1142)
parent
437fb2cb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
4 deletions
+10
-4
link.js
lib/link.js
+2
-2
router.js
lib/router/router.js
+3
-2
utils.js
lib/utils.js
+5
-0
No files found.
lib/link.js
View file @
d382e4db
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'
import
{
warn
,
execOnce
,
getLocationOrigin
}
from
'./utils'
export
default
class
Link
extends
Component
{
export
default
class
Link
extends
Component
{
constructor
(
props
)
{
constructor
(
props
)
{
...
@@ -84,7 +84,7 @@ export default class Link extends Component {
...
@@ -84,7 +84,7 @@ export default class Link extends Component {
}
}
export
function
isLocal
(
href
)
{
export
function
isLocal
(
href
)
{
const
origin
=
window
.
location
.
origin
const
origin
=
getLocationOrigin
()
return
!
/^
(
https
?
:
)?\/\/
/
.
test
(
href
)
||
return
!
/^
(
https
?
:
)?\/\/
/
.
test
(
href
)
||
origin
===
href
.
substr
(
0
,
origin
.
length
)
origin
===
href
.
substr
(
0
,
origin
.
length
)
}
}
...
...
lib/router/router.js
View file @
d382e4db
...
@@ -5,7 +5,7 @@ import evalScript from '../eval-script'
...
@@ -5,7 +5,7 @@ import evalScript from '../eval-script'
import
shallowEquals
from
'../shallow-equals'
import
shallowEquals
from
'../shallow-equals'
import
{
EventEmitter
}
from
'events'
import
{
EventEmitter
}
from
'events'
import
{
reloadIfPrefetched
}
from
'../prefetch'
import
{
reloadIfPrefetched
}
from
'../prefetch'
import
{
loadGetInitialProps
}
from
'../utils'
import
{
loadGetInitialProps
,
getLocationOrigin
}
from
'../utils'
export
default
class
Router
extends
EventEmitter
{
export
default
class
Router
extends
EventEmitter
{
constructor
(
pathname
,
query
,
{
Component
,
ErrorComponent
,
err
}
=
{})
{
constructor
(
pathname
,
query
,
{
Component
,
ErrorComponent
,
err
}
=
{})
{
...
@@ -283,7 +283,8 @@ export default class Router extends EventEmitter {
...
@@ -283,7 +283,8 @@ export default class Router extends EventEmitter {
}
}
function
getURL
()
{
function
getURL
()
{
const
{
href
,
origin
}
=
window
.
location
const
{
href
}
=
window
.
location
const
origin
=
getLocationOrigin
()
return
href
.
substring
(
origin
.
length
)
return
href
.
substring
(
origin
.
length
)
}
}
...
...
lib/utils.js
View file @
d382e4db
...
@@ -53,3 +53,8 @@ export async function loadGetInitialProps (Component, ctx) {
...
@@ -53,3 +53,8 @@ export async function loadGetInitialProps (Component, ctx) {
}
}
return
props
return
props
}
}
export
function
getLocationOrigin
()
{
const
{
protocol
,
hostname
,
port
}
=
window
.
location
return
`
${
protocol
}
//
${
hostname
}${
port
?
':'
+
port
:
''
}
`
}
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