Skip to content

Commit e44fb85

Browse files
committed
fix(base): google cache issue: vuejs#2042
1 parent 732c825 commit e44fb85

7 files changed

+58
-46
lines changed

dist/vue-router.common.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -1389,10 +1389,8 @@ function createMatcher (
13891389
}
13901390
}
13911391

1392-
if (record) {
1393-
location.path = fillParams(record.path, location.params, ("named route \"" + name + "\""));
1394-
return _createRoute(record, location, redirectedFrom)
1395-
}
1392+
location.path = fillParams(record.path, location.params, ("named route \"" + name + "\""));
1393+
return _createRoute(record, location, redirectedFrom)
13961394
} else if (location.path) {
13971395
location.params = {};
13981396
for (var i = 0; i < pathList.length; i++) {
@@ -1547,7 +1545,12 @@ var positionStore = Object.create(null);
15471545
function setupScroll () {
15481546
// Fix for #1585 for Firefox
15491547
// Fix for #2195 Add optional third attribute to workaround a bug in safari https://bugs.webkit.org/show_bug.cgi?id=182678
1550-
window.history.replaceState({ key: getStateKey() }, '', window.location.href.replace(window.location.origin, ''));
1548+
// Fix for #2774 Support for apps loaded from Windows file shares not mapped to network drives: replaced location.origin with
1549+
// window.location.protocol + '//' + window.location.host
1550+
// location.host contains the port and location.hostname doesn't
1551+
var protocolAndPath = window.location.protocol + '//' + window.location.host;
1552+
var absolutePath = window.location.href.replace(protocolAndPath, '');
1553+
window.history.replaceState({ key: getStateKey() }, '', absolutePath);
15511554
window.addEventListener('popstate', function (e) {
15521555
saveScrollPosition();
15531556
if (e.state && e.state.key) {
@@ -2022,10 +2025,10 @@ function normalizeBase (base) {
20222025
if (!base) {
20232026
if (inBrowser) {
20242027
// respect <base> tag
2025-
var baseEl = document.querySelector('base');
2026-
base = (baseEl && baseEl.getAttribute('href')) || '/';
2027-
// strip full URL origin
2028-
base = base.replace(/^https?:\/\/[^\/]+/, '');
2028+
var baseURI = document.baseURI || '/';
2029+
var a = document.createElement('a');
2030+
a.href = baseURI;
2031+
base = a.pathname;
20292032
} else {
20302033
base = '/';
20312034
}
@@ -2119,7 +2122,6 @@ function bindEnterGuard (
21192122
) {
21202123
return function routeEnterGuard (to, from, next) {
21212124
return guard(to, from, function (cb) {
2122-
next(cb);
21232125
if (typeof cb === 'function') {
21242126
cbs.push(function () {
21252127
// #750
@@ -2130,6 +2132,7 @@ function bindEnterGuard (
21302132
poll(cb, match.instances, key, isValid);
21312133
});
21322134
}
2135+
next(cb);
21332136
})
21342137
}
21352138
}

dist/vue-router.esm.browser.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -1364,10 +1364,8 @@ function createMatcher (
13641364
}
13651365
}
13661366

1367-
if (record) {
1368-
location.path = fillParams(record.path, location.params, `named route "${name}"`);
1369-
return _createRoute(record, location, redirectedFrom)
1370-
}
1367+
location.path = fillParams(record.path, location.params, `named route "${name}"`);
1368+
return _createRoute(record, location, redirectedFrom)
13711369
} else if (location.path) {
13721370
location.params = {};
13731371
for (let i = 0; i < pathList.length; i++) {
@@ -1519,7 +1517,12 @@ const positionStore = Object.create(null);
15191517
function setupScroll () {
15201518
// Fix for #1585 for Firefox
15211519
// Fix for #2195 Add optional third attribute to workaround a bug in safari https://bugs.webkit.org/show_bug.cgi?id=182678
1522-
window.history.replaceState({ key: getStateKey() }, '', window.location.href.replace(window.location.origin, ''));
1520+
// Fix for #2774 Support for apps loaded from Windows file shares not mapped to network drives: replaced location.origin with
1521+
// window.location.protocol + '//' + window.location.host
1522+
// location.host contains the port and location.hostname doesn't
1523+
const protocolAndPath = window.location.protocol + '//' + window.location.host;
1524+
const absolutePath = window.location.href.replace(protocolAndPath, '');
1525+
window.history.replaceState({ key: getStateKey() }, '', absolutePath);
15231526
window.addEventListener('popstate', e => {
15241527
saveScrollPosition();
15251528
if (e.state && e.state.key) {
@@ -2007,10 +2010,10 @@ function normalizeBase (base) {
20072010
if (!base) {
20082011
if (inBrowser) {
20092012
// respect <base> tag
2010-
const baseEl = document.querySelector('base');
2011-
base = (baseEl && baseEl.getAttribute('href')) || '/';
2012-
// strip full URL origin
2013-
base = base.replace(/^https?:\/\/[^\/]+/, '');
2013+
const baseURI = document.baseURI || '/';
2014+
const a = document.createElement('a');
2015+
a.href = baseURI;
2016+
base = a.pathname;
20142017
} else {
20152018
base = '/';
20162019
}
@@ -2104,7 +2107,6 @@ function bindEnterGuard (
21042107
) {
21052108
return function routeEnterGuard (to, from, next) {
21062109
return guard(to, from, cb => {
2107-
next(cb);
21082110
if (typeof cb === 'function') {
21092111
cbs.push(() => {
21102112
// #750
@@ -2115,6 +2117,7 @@ function bindEnterGuard (
21152117
poll(cb, match.instances, key, isValid);
21162118
});
21172119
}
2120+
next(cb);
21182121
})
21192122
}
21202123
}

dist/vue-router.esm.browser.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue-router.esm.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -1387,10 +1387,8 @@ function createMatcher (
13871387
}
13881388
}
13891389

1390-
if (record) {
1391-
location.path = fillParams(record.path, location.params, ("named route \"" + name + "\""));
1392-
return _createRoute(record, location, redirectedFrom)
1393-
}
1390+
location.path = fillParams(record.path, location.params, ("named route \"" + name + "\""));
1391+
return _createRoute(record, location, redirectedFrom)
13941392
} else if (location.path) {
13951393
location.params = {};
13961394
for (var i = 0; i < pathList.length; i++) {
@@ -1545,7 +1543,12 @@ var positionStore = Object.create(null);
15451543
function setupScroll () {
15461544
// Fix for #1585 for Firefox
15471545
// Fix for #2195 Add optional third attribute to workaround a bug in safari https://bugs.webkit.org/show_bug.cgi?id=182678
1548-
window.history.replaceState({ key: getStateKey() }, '', window.location.href.replace(window.location.origin, ''));
1546+
// Fix for #2774 Support for apps loaded from Windows file shares not mapped to network drives: replaced location.origin with
1547+
// window.location.protocol + '//' + window.location.host
1548+
// location.host contains the port and location.hostname doesn't
1549+
var protocolAndPath = window.location.protocol + '//' + window.location.host;
1550+
var absolutePath = window.location.href.replace(protocolAndPath, '');
1551+
window.history.replaceState({ key: getStateKey() }, '', absolutePath);
15491552
window.addEventListener('popstate', function (e) {
15501553
saveScrollPosition();
15511554
if (e.state && e.state.key) {
@@ -2020,10 +2023,10 @@ function normalizeBase (base) {
20202023
if (!base) {
20212024
if (inBrowser) {
20222025
// respect <base> tag
2023-
var baseEl = document.querySelector('base');
2024-
base = (baseEl && baseEl.getAttribute('href')) || '/';
2025-
// strip full URL origin
2026-
base = base.replace(/^https?:\/\/[^\/]+/, '');
2026+
var baseURI = document.baseURI || '/';
2027+
var a = document.createElement('a');
2028+
a.href = baseURI;
2029+
base = a.pathname;
20272030
} else {
20282031
base = '/';
20292032
}
@@ -2117,7 +2120,6 @@ function bindEnterGuard (
21172120
) {
21182121
return function routeEnterGuard (to, from, next) {
21192122
return guard(to, from, function (cb) {
2120-
next(cb);
21212123
if (typeof cb === 'function') {
21222124
cbs.push(function () {
21232125
// #750
@@ -2128,6 +2130,7 @@ function bindEnterGuard (
21282130
poll(cb, match.instances, key, isValid);
21292131
});
21302132
}
2133+
next(cb);
21312134
})
21322135
}
21332136
}

dist/vue-router.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -1393,10 +1393,8 @@ function createMatcher (
13931393
}
13941394
}
13951395

1396-
if (record) {
1397-
location.path = fillParams(record.path, location.params, ("named route \"" + name + "\""));
1398-
return _createRoute(record, location, redirectedFrom)
1399-
}
1396+
location.path = fillParams(record.path, location.params, ("named route \"" + name + "\""));
1397+
return _createRoute(record, location, redirectedFrom)
14001398
} else if (location.path) {
14011399
location.params = {};
14021400
for (var i = 0; i < pathList.length; i++) {
@@ -1551,7 +1549,12 @@ var positionStore = Object.create(null);
15511549
function setupScroll () {
15521550
// Fix for #1585 for Firefox
15531551
// Fix for #2195 Add optional third attribute to workaround a bug in safari https://bugs.webkit.org/show_bug.cgi?id=182678
1554-
window.history.replaceState({ key: getStateKey() }, '', window.location.href.replace(window.location.origin, ''));
1552+
// Fix for #2774 Support for apps loaded from Windows file shares not mapped to network drives: replaced location.origin with
1553+
// window.location.protocol + '//' + window.location.host
1554+
// location.host contains the port and location.hostname doesn't
1555+
var protocolAndPath = window.location.protocol + '//' + window.location.host;
1556+
var absolutePath = window.location.href.replace(protocolAndPath, '');
1557+
window.history.replaceState({ key: getStateKey() }, '', absolutePath);
15551558
window.addEventListener('popstate', function (e) {
15561559
saveScrollPosition();
15571560
if (e.state && e.state.key) {
@@ -2026,10 +2029,10 @@ function normalizeBase (base) {
20262029
if (!base) {
20272030
if (inBrowser) {
20282031
// respect <base> tag
2029-
var baseEl = document.querySelector('base');
2030-
base = (baseEl && baseEl.getAttribute('href')) || '/';
2031-
// strip full URL origin
2032-
base = base.replace(/^https?:\/\/[^\/]+/, '');
2032+
var baseURI = document.baseURI || '/';
2033+
var a = document.createElement('a');
2034+
a.href = baseURI;
2035+
base = a.pathname;
20332036
} else {
20342037
base = '/';
20352038
}
@@ -2123,7 +2126,6 @@ function bindEnterGuard (
21232126
) {
21242127
return function routeEnterGuard (to, from, next) {
21252128
return guard(to, from, function (cb) {
2126-
next(cb);
21272129
if (typeof cb === 'function') {
21282130
cbs.push(function () {
21292131
// #750
@@ -2134,6 +2136,7 @@ function bindEnterGuard (
21342136
poll(cb, match.instances, key, isValid);
21352137
});
21362138
}
2139+
next(cb);
21372140
})
21382141
}
21392142
}

dist/vue-router.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/history/base.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ function normalizeBase (base: ?string): string {
196196
if (!base) {
197197
if (inBrowser) {
198198
// respect <base> tag
199-
const baseEl = document.querySelector('base')
200-
base = (baseEl && baseEl.getAttribute('href')) || '/'
201-
// strip full URL origin
202-
base = base.replace(/^https?:\/\/[^\/]+/, '')
199+
const baseURI = document.baseURI || '/'
200+
const a = document.createElement('a')
201+
a.href = baseURI
202+
base = a.pathname
203203
} else {
204204
base = '/'
205205
}

0 commit comments

Comments
 (0)