Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/link.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { resolve } from 'url'
import React, { Component, Children, PropTypes } from 'react'
import Router from './router'

Expand All @@ -21,13 +22,17 @@ export default class Link extends Component {
return
}

const { href, as = href } = this.props
let { href, as } = this.props

if (!isLocal(href)) {
// ignore click if it's outside our scope
return
}

const { pathname } = window.location
href = resolve(pathname, href)
as = as ? resolve(pathname, as) : href

e.preventDefault()

// avoid scroll for urls with anchor refs
Expand Down Expand Up @@ -74,6 +79,6 @@ export default class Link extends Component {

export function isLocal (href) {
const origin = window.location.origin
return !/^https?:\/\//.test(href) ||
return !/^(https?:)?\/\//.test(href) ||
origin === href.substr(0, origin.length)
}
2 changes: 1 addition & 1 deletion lib/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class Router extends EventEmitter {
async onPopState (e) {
this.abortComponentLoad()

const { url, as } = e.state
const { url = getURL(), as = url } = e.state || {}
const { pathname, query } = parse(url, true)

if (!this.urlIsNew(pathname, query)) {
Expand Down