提交 d382e4db 编写于 作者: E Eric Zingeler 提交者: Arunoda Susiripala

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

上级 437fb2cb
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)
}
......
......@@ -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)
}
......
......@@ -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 : ''}`
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册