Skip to content

Commit 16b5ba5

Browse files
fix: files from basePath should be remoteUrl:false
1 parent c3cdadc commit 16b5ba5

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

Diff for: src/core/fetch/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ export function fetchMixin(proto) {
7676
};
7777

7878
proto._fetch = function(cb = noop) {
79+
const { basePath } = this.config;
7980
const { query } = this.route;
8081
let { path } = this.route;
8182

8283
// Prevent loading remote content via URL hash
8384
// Ex: https://foo.com/#//bar.com/file.md
84-
if (isExternal(path)) {
85+
if (isExternal(path, basePath)) {
8586
history.replaceState(null, '', '#');
8687
this.router.normalize();
8788
} else {
@@ -92,7 +93,7 @@ export function fetchMixin(proto) {
9293
const file = this.router.getFile(path);
9394
const req = request(file + qs, true, requestHeaders);
9495

95-
this.isRemoteUrl = isExternal(file);
96+
this.isRemoteUrl = isExternal(file, basePath);
9697
// Current page is html
9798
this.isHTML = /\.html$/g.test(file);
9899

Diff for: src/core/util/core.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,20 @@ export function isFn(obj) {
7272
* @param {String} string url
7373
* @returns {Boolean} True if the passed-in url is external
7474
*/
75-
export function isExternal(url) {
76-
let match = url.match(
77-
/^([^:/?#]+:)?(?:\/{2,}([^/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/
78-
);
75+
export function isExternal(url, basePath) {
76+
const regExp = /^([^:/?#]+:)?(?:\/{2,}([^/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/;
77+
let match = url.match(regExp);
78+
79+
if (basePath) {
80+
const matchWithBasePath = basePath.match(regExp);
81+
if (
82+
match && matchWithBasePath &&
83+
match[1] === matchWithBasePath[1] &&
84+
match[2] === matchWithBasePath[2]
85+
) {
86+
return false;
87+
}
88+
}
7989

8090
if (
8191
typeof match[1] === 'string' &&

0 commit comments

Comments
 (0)