diff --git a/cypress/fixtures/tpl/docs.index.html b/cypress/fixtures/tpl/docs.index.html index a4b4c831f..3ffe35230 100644 --- a/cypress/fixtures/tpl/docs.index.html +++ b/cypress/fixtures/tpl/docs.index.html @@ -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/(.*)': @@ -40,6 +40,7 @@ '/es/(.*)': 'https://raw.githubusercontent.com/docsifyjs/docs-es/master/$1' }, + fallbackLanguages: ['es'], auto2top: true, coverpage: true, executeScript: true, diff --git a/cypress/integration/routing/fallback.spec.js b/cypress/integration/routing/fallback.spec.js new file mode 100644 index 000000000..2e9951102 --- /dev/null +++ b/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'); + }) +}); diff --git a/src/core/fetch/index.js b/src/core/fetch/index.js index 9d2769b84..6bf592c96 100644 --- a/src/core/fetch/index.js +++ b/src/core/fetch/index.js @@ -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); } ); @@ -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(