Skip to content

Commit

Permalink
feat: priority use document.baseURI to replace window.location
Browse files Browse the repository at this point in the history
- respect `<base>` tag

in case: when view page cache, search engine will inject `<base>` tag to current html
but `window.location` is still `webcache.googleusercontent.com/search?q=cache:...`

in most situation `baseURI` is equal to `window.location`
  • Loading branch information
sabakugaara committed May 22, 2017
1 parent 55373ec commit 7a76f2f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
9 changes: 1 addition & 8 deletions src/history/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { _Vue } from '../install'
import type Router from '../index'
import { warn } from '../util/warn'
import { inBrowser } from '../util/dom'
import { runQueue } from '../util/async'
import { START, isSameRoute } from '../util/route'

Expand Down Expand Up @@ -189,13 +188,7 @@ export class History {

function normalizeBase (base: ?string): string {
if (!base) {
if (inBrowser) {
// respect <base> tag
const baseEl = document.querySelector('base')
base = (baseEl && baseEl.getAttribute('href')) || '/'
} else {
base = '/'
}
base = '/'
}
// make sure there's the starting slash
if (base.charAt(0) !== '/') {
Expand Down
7 changes: 7 additions & 0 deletions src/history/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ export class HTML5History extends History {

export function getLocation (base: string): string {
let path = window.location.pathname
const baseURI = document.baseURI
if (baseURI) {
const a = document.createElement('a')
a.href = baseURI
path = a.pathname
}

if (base && path.indexOf(base) === 0) {
path = path.slice(base.length)
}
Expand Down
3 changes: 0 additions & 3 deletions src/util/dom.js

This file was deleted.

0 comments on commit 7a76f2f

Please sign in to comment.