From de4e17b76e5d09c4c32a48c2d852e63b0f4db977 Mon Sep 17 00:00:00 2001 From: Sonu Kapoor Date: Sat, 22 Feb 2020 17:18:01 -0500 Subject: [PATCH] fix(docs-infra): fix redirect in angular version selector (#35632) Closes #35630 PR Close #35632 --- aio/src/app/app.component.spec.ts | 9 +++++++++ aio/src/app/app.component.ts | 7 ++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/aio/src/app/app.component.spec.ts b/aio/src/app/app.component.spec.ts index 62f345f859..ce1c4d75c3 100644 --- a/aio/src/app/app.component.spec.ts +++ b/aio/src/app/app.component.spec.ts @@ -417,6 +417,15 @@ describe('AppComponent', () => { selectElement.triggerEventHandler('change', { option: versionWithoutUrl, index: versionWithoutUrlIndex }); expect(locationService.go).not.toHaveBeenCalled(); }); + + it('should navigate when change to a version with a url that does not end with `/`', async () => { + await setupSelectorForTesting(); + locationService.urlSubject.next('docs#section-1'); + const versionWithoutSlashIndex = component.docVersions.length; + const versionWithoutSlashUrl = component.docVersions[versionWithoutSlashIndex] = { url: 'https://next.angular.io', title: 'foo' }; + selectElement.triggerEventHandler('change', { option: versionWithoutSlashUrl, index: versionWithoutSlashIndex }); + expect(locationService.go).toHaveBeenCalledWith('https://next.angular.io/docs#section-1'); + }); }); describe('currentDocument', () => { diff --git a/aio/src/app/app.component.ts b/aio/src/app/app.component.ts index b5fa56c11d..bedd804613 100644 --- a/aio/src/app/app.component.ts +++ b/aio/src/app/app.component.ts @@ -149,8 +149,8 @@ export class AppComponent implements OnInit { ]).subscribe(([versionInfo, versions]) => { // TODO(pbd): consider whether we can lookup the stable and next versions from the internet const computedVersions: NavigationNode[] = [ - { title: 'next', url: 'https://next.angular.io' }, - { title: 'stable', url: 'https://angular.io' }, + { title: 'next', url: 'https://next.angular.io/' }, + { title: 'stable', url: 'https://angular.io/' }, ]; if (this.deployment.mode === 'archive') { computedVersions.push({ title: `v${versionInfo.major}` }); @@ -232,7 +232,8 @@ export class AppComponent implements OnInit { onDocVersionChange(versionIndex: number) { const version = this.docVersions[versionIndex]; if (version.url) { - this.locationService.go(`${version.url}${this.currentUrl}`); + const versionUrl = version.url + (!version.url.endsWith('/') ? '/' : ''); + this.locationService.go(`${versionUrl}${this.currentUrl}`); } }