1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

replace location.origin usage with new utils/getLocationOrigin (#1142)

This commit is contained in:
Eric Zingeler 2017-02-15 00:31:19 -08:00 committed by Arunoda Susiripala
parent 437fb2cbd3
commit d382e4db9a
3 changed files with 10 additions and 4 deletions

View file

@ -1,7 +1,7 @@
import { resolve } from 'url'
import React, { Component, Children, PropTypes } from 'react'
import Router from './router'
import { warn, execOnce } from './utils'
import { warn, execOnce, getLocationOrigin } from './utils'
export default class Link extends Component {
constructor (props) {
@ -84,7 +84,7 @@ export default class Link extends Component {
}
export function isLocal (href) {
const origin = window.location.origin
const origin = getLocationOrigin()
return !/^(https?:)?\/\//.test(href) ||
origin === href.substr(0, origin.length)
}

View file

@ -5,7 +5,7 @@ import evalScript from '../eval-script'
import shallowEquals from '../shallow-equals'
import { EventEmitter } from 'events'
import { reloadIfPrefetched } from '../prefetch'
import { loadGetInitialProps } from '../utils'
import { loadGetInitialProps, getLocationOrigin } from '../utils'
export default class Router extends EventEmitter {
constructor (pathname, query, { Component, ErrorComponent, err } = {}) {
@ -283,7 +283,8 @@ export default class Router extends EventEmitter {
}
function getURL () {
const { href, origin } = window.location
const { href } = window.location
const origin = getLocationOrigin()
return href.substring(origin.length)
}

View file

@ -53,3 +53,8 @@ export async function loadGetInitialProps (Component, ctx) {
}
return props
}
export function getLocationOrigin () {
const { protocol, hostname, port } = window.location
return `${protocol}//${hostname}${port ? ':' + port : ''}`
}