From 1b82c5d88dd75a2397e99c9c5ece22554eaa4dde Mon Sep 17 00:00:00 2001 From: Gaara Date: Mon, 22 May 2017 12:37:05 +0800 Subject: [PATCH 1/8] fix: not respect base tag - respect `` tag in case: when view page cache, search engine will inject `` tag to current html but `window.location` is still `webcache.googleusercontent.com/search?q=cache:...` in most situation `baseURI` is equal to `window.location` --- src/history/base.js | 9 +-------- src/history/hash.js | 2 +- src/history/html5.js | 7 +++++++ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/history/base.js b/src/history/base.js index 7228061d3..c06faf7b9 100644 --- a/src/history/base.js +++ b/src/history/base.js @@ -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' @@ -189,13 +188,7 @@ export class History { function normalizeBase (base: ?string): string { if (!base) { - if (inBrowser) { - // respect 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) !== '/') { diff --git a/src/history/hash.js b/src/history/hash.js index 501f4844b..57d1957e7 100644 --- a/src/history/hash.js +++ b/src/history/hash.js @@ -80,7 +80,7 @@ function ensureSlash (): boolean { export function getHash (): string { // We can't use window.location.hash here because it's not // consistent across browsers - Firefox will pre-decode it! - const href = window.location.href + const href = document.baseURI || window.location.href const index = href.indexOf('#') return index === -1 ? '' : href.slice(index + 1) } diff --git a/src/history/html5.js b/src/history/html5.js index 55df57fbd..6238d1a37 100644 --- a/src/history/html5.js +++ b/src/history/html5.js @@ -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) } From 5aaa7d13aa8e175bbc2bb1fbc160473c1963a19e Mon Sep 17 00:00:00 2001 From: Gaara Date: Mon, 22 May 2017 13:16:45 +0800 Subject: [PATCH 2/8] fix hash doesn't change when repect document.baseURI In hash mode, maybe should ignore baseURI --- src/history/hash.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/history/hash.js b/src/history/hash.js index 57d1957e7..501f4844b 100644 --- a/src/history/hash.js +++ b/src/history/hash.js @@ -80,7 +80,7 @@ function ensureSlash (): boolean { export function getHash (): string { // We can't use window.location.hash here because it's not // consistent across browsers - Firefox will pre-decode it! - const href = document.baseURI || window.location.href + const href = window.location.href const index = href.indexOf('#') return index === -1 ? '' : href.slice(index + 1) } From 97f5f1891203764f8335f768ae915187b42d81e1 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 16 Jun 2017 16:04:43 +0800 Subject: [PATCH 3/8] reuse base parser --- src/history/html5.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/history/html5.js b/src/history/html5.js index 6238d1a37..425d75fe9 100644 --- a/src/history/html5.js +++ b/src/history/html5.js @@ -59,13 +59,15 @@ export class HTML5History extends History { } } +let baseParser + 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 + baseParser = baseParser || document.createElement('a') + baseParser.href = baseURI + path = baseParser.pathname } if (base && path.indexOf(base) === 0) { From 9c8d28cc6a7dab1af618fd971118b5587991bb50 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 16 Jun 2017 16:11:40 +0800 Subject: [PATCH 4/8] Update base.js --- src/history/base.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/history/base.js b/src/history/base.js index c06faf7b9..484cb7a94 100644 --- a/src/history/base.js +++ b/src/history/base.js @@ -186,10 +186,7 @@ export class History { } } -function normalizeBase (base: ?string): string { - if (!base) { - base = '/' - } +function normalizeBase (base: ?string = ''): string { // make sure there's the starting slash if (base.charAt(0) !== '/') { base = '/' + base From 9b7c178be436db470d6f1b7e7c34876e9a88187e Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 16 Jun 2017 16:26:59 +0800 Subject: [PATCH 5/8] Update base.js --- src/history/base.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/history/base.js b/src/history/base.js index 484cb7a94..d322b18d6 100644 --- a/src/history/base.js +++ b/src/history/base.js @@ -186,7 +186,8 @@ export class History { } } -function normalizeBase (base: ?string = ''): string { +function normalizeBase (base: ?string): string { + base = base || '' // make sure there's the starting slash if (base.charAt(0) !== '/') { base = '/' + base From 917c9c462c40cbdc6544f08fdea0544bb4d73571 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 16 Jun 2017 23:40:01 +0800 Subject: [PATCH 6/8] Update html5.js --- src/history/html5.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/history/html5.js b/src/history/html5.js index 425d75fe9..55df57fbd 100644 --- a/src/history/html5.js +++ b/src/history/html5.js @@ -59,17 +59,8 @@ export class HTML5History extends History { } } -let baseParser - export function getLocation (base: string): string { let path = window.location.pathname - const baseURI = document.baseURI - if (baseURI) { - baseParser = baseParser || document.createElement('a') - baseParser.href = baseURI - path = baseParser.pathname - } - if (base && path.indexOf(base) === 0) { path = path.slice(base.length) } From bbfc09605417750569ae92a8b59b3bd63d4024cb Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 16 Jun 2017 23:41:08 +0800 Subject: [PATCH 7/8] Update base.js --- src/history/base.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/history/base.js b/src/history/base.js index d322b18d6..00a6e71f1 100644 --- a/src/history/base.js +++ b/src/history/base.js @@ -187,7 +187,18 @@ export class History { } function normalizeBase (base: ?string): string { - base = base || '' + // respect tag + if (!base) { + if (inBrowser) { + // respect tag + const baseURI = document.baseURI || '/' + const a = document.createElement('a') + a.href = baseURI + base = a.pathname + } else { + base = '/' + } + } // make sure there's the starting slash if (base.charAt(0) !== '/') { base = '/' + base From 6efac0473cedc98c2b546c3399e302c947d140fb Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 16 Jun 2017 23:45:38 +0800 Subject: [PATCH 8/8] Update base.js --- src/history/base.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/history/base.js b/src/history/base.js index 00a6e71f1..7b002a40f 100644 --- a/src/history/base.js +++ b/src/history/base.js @@ -3,6 +3,7 @@ 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'