Skip to content

Commit

Permalink
fix: fallback page should use path not file location (#1301)
Browse files Browse the repository at this point in the history
* 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: 沈唁 <52o@qq52o.cn>
  • Loading branch information
palkan and sy-records committed Aug 4, 2020
1 parent 750663e commit 2bceabc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cypress/fixtures/tpl/docs.index.html
Expand Up @@ -28,7 +28,7 @@
alias: {
'.*?/awesome':
'https://raw.githubusercontent.com/docsifyjs/awesome-docsify/master/README.md',
'.*?/changelog':
'/changelog':
'https://raw.githubusercontent.com/docsifyjs/docsify/master/CHANGELOG.md',
'/.*/_navbar.md': '/_navbar.md',
'/zh-cn/(.*)':
Expand All @@ -40,6 +40,7 @@
'/es/(.*)':
'https://raw.githubusercontent.com/docsifyjs/docs-es/master/$1'
},
fallbackLanguages: ['es'],
auto2top: true,
coverpage: true,
executeScript: true,
Expand Down
9 changes: 9 additions & 0 deletions cypress/integration/routing/fallback.spec.js
@@ -0,0 +1,9 @@
context('config.fallbackLanguages', () => {
it('fallbacks respecting aliases', () => {
cy.visit('http://localhost:3000/#/es/');

cy.get('.sidebar-nav').contains('Changelog').click();

cy.get('#main').should('contain', 'Bug Fixes');
})
});
6 changes: 4 additions & 2 deletions src/core/fetch/index.js
Expand Up @@ -123,7 +123,7 @@ export function fetchMixin(proto) {
this._loadSideAndNav(path, qs, loadSidebar, cb)
),
_ => {
this._fetchFallbackPage(file, qs, cb) || this._fetch404(file, qs, cb);
this._fetchFallbackPage(path, qs, cb) || this._fetch404(file, qs, cb);
}
);

Expand Down Expand Up @@ -209,7 +209,9 @@ export function fetchMixin(proto) {
return false;
}

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

req.then(
Expand Down

1 comment on commit 2bceabc

@vercel
Copy link

@vercel vercel bot commented on 2bceabc Aug 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.