Skip to content

Commit 7a76f2f

Browse files
committed
feat: priority use document.baseURI to replace window.location
- 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`
1 parent 55373ec commit 7a76f2f

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

src/history/base.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import { _Vue } from '../install'
44
import type Router from '../index'
55
import { warn } from '../util/warn'
6-
import { inBrowser } from '../util/dom'
76
import { runQueue } from '../util/async'
87
import { START, isSameRoute } from '../util/route'
98

@@ -189,13 +188,7 @@ export class History {
189188

190189
function normalizeBase (base: ?string): string {
191190
if (!base) {
192-
if (inBrowser) {
193-
// respect <base> tag
194-
const baseEl = document.querySelector('base')
195-
base = (baseEl && baseEl.getAttribute('href')) || '/'
196-
} else {
197-
base = '/'
198-
}
191+
base = '/'
199192
}
200193
// make sure there's the starting slash
201194
if (base.charAt(0) !== '/') {

src/history/html5.js

+7
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ export class HTML5History extends History {
6161

6262
export function getLocation (base: string): string {
6363
let path = window.location.pathname
64+
const baseURI = document.baseURI
65+
if (baseURI) {
66+
const a = document.createElement('a')
67+
a.href = baseURI
68+
path = a.pathname
69+
}
70+
6471
if (base && path.indexOf(base) === 0) {
6572
path = path.slice(base.length)
6673
}

src/util/dom.js

-3
This file was deleted.

0 commit comments

Comments
 (0)