Skip to content

Commit 2bceabc

Browse files
palkansy-records
andauthored
fix: fallback page should use path not file location (#1301)
* fix: fallback page should use path not file location When resolving fallback page for the path (`fallbackLanguages` option), we should consider the original path, not the file location (which could be different when aliases are used). * fix: use router.getFile to resolve fallback url * specs: add cypress test for fallbackLanguages Co-authored-by: 沈唁 <[email protected]>
1 parent 750663e commit 2bceabc

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

Diff for: cypress/fixtures/tpl/docs.index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
alias: {
2929
'.*?/awesome':
3030
'https://raw.githubusercontent.com/docsifyjs/awesome-docsify/master/README.md',
31-
'.*?/changelog':
31+
'/changelog':
3232
'https://raw.githubusercontent.com/docsifyjs/docsify/master/CHANGELOG.md',
3333
'/.*/_navbar.md': '/_navbar.md',
3434
'/zh-cn/(.*)':
@@ -40,6 +40,7 @@
4040
'/es/(.*)':
4141
'https://raw.githubusercontent.com/docsifyjs/docs-es/master/$1'
4242
},
43+
fallbackLanguages: ['es'],
4344
auto2top: true,
4445
coverpage: true,
4546
executeScript: true,

Diff for: cypress/integration/routing/fallback.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
context('config.fallbackLanguages', () => {
2+
it('fallbacks respecting aliases', () => {
3+
cy.visit('http://localhost:3000/#/es/');
4+
5+
cy.get('.sidebar-nav').contains('Changelog').click();
6+
7+
cy.get('#main').should('contain', 'Bug Fixes');
8+
})
9+
});

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export function fetchMixin(proto) {
123123
this._loadSideAndNav(path, qs, loadSidebar, cb)
124124
),
125125
_ => {
126-
this._fetchFallbackPage(file, qs, cb) || this._fetch404(file, qs, cb);
126+
this._fetchFallbackPage(path, qs, cb) || this._fetch404(file, qs, cb);
127127
}
128128
);
129129

@@ -209,7 +209,9 @@ export function fetchMixin(proto) {
209209
return false;
210210
}
211211

212-
const newPath = path.replace(new RegExp(`^/${local}`), '');
212+
const newPath = this.router.getFile(
213+
path.replace(new RegExp(`^/${local}`), '')
214+
);
213215
const req = request(newPath + qs, true, requestHeaders);
214216

215217
req.then(

0 commit comments

Comments
 (0)